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

  • 相关阅读:
    MT【160】格点
    MT【159】单调有界有极限
    c_str() 函数
    C strstr() 函数
    全面总结:matlab怎么做漂亮的图
    程序员电邮札记
    C编译: 使用gdb调试
    C编译: 动态连接库 (.so文件)
    C编译: makefile基础
    数据科学
  • 原文地址:https://www.cnblogs.com/gc2013/p/4000647.html
Copyright © 2011-2022 走看看