zoukankan      html  css  js  c++  java
  • c#实现随鼠标移动窗体

    1. private void MainForm_Load(object sender, EventArgs e)  
    2. {  
    3.     //绑定事件  
    4.     MouseMove += Form_MouseMove;  
    5.     MouseDown += Form_MouseDown;  
    6. }  
    7. private Point _mousePoint;  
    8. private void Form_MouseMove(object sender, MouseEventArgs e)  
    9. {  
    10.     if (e.Button == MouseButtons.Left)  
    11.     {  
    12.         Top = MousePosition.Y - _mousePoint.Y;  
    13.         Left = MousePosition.X - _mousePoint.X;  
    14.     }  
    15. }  
    16. private void Form_MouseDown(object sender, MouseEventArgs e)  
    17. {  
    18.     if (e.Button == MouseButtons.Left)  
    19.     {  
    20.         _mousePoint.X = e.X;  
    21.         _mousePoint.Y = e.Y;  
    22.     }  
    23. }  

    如果窗体有标题 
    Top -= SystemInformation.CaptionHeight;

    如果有边框 
    Top -= SystemInformation.FormBorderSize.Height
    Left -= SystemInformation.FormBorderSize.Width

  • 相关阅读:
    为什么硬链接不能链接目录、文件inode 和目录 dentry 的区别联系
    LVM 详解
    pwd 命令详解
    type 命令详解
    查看文件中字符出现次数
    lesson
    xml linq
    新系统配置
    空合并运算符(??):
    dos.ORM配置和使用
  • 原文地址:https://www.cnblogs.com/gc2013/p/4000647.html
Copyright © 2011-2022 走看看