• c# WinForm 中鼠标控制窗体的移动


     

    初步找到两个方法

    方法1:这种方法还没有尝试过


    private const int wm_nchittest = 0x84;
            
    private const int htclient = 0x1;
            
    private const int htcaption = 0x2;
            
    protected override void WndProc(ref System.Windows.Forms.Message m)
            {
                
    switch (m.Msg)
                {
                    
    case wm_nchittest:
                        
    base.WndProc(ref m);
                        
    if ((int)m.Result == htclient)
                            m.Result 
    = (IntPtr)htcaption;
                        
    return;
                }
                
    base.WndProc(ref m);
            }


    方法2:已经试过很多次,感觉比较通俗易懂^_^

    private Point mouse_offset = new Point(0,0);

    private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
                
    this.mouse_offset = new Point(-e.X,-e.Y);
    }

    private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
                
    if(e.Button == MouseButtons.Left)
               {
                     Point mousepos 
    = Control.MousePosition;
                     mousepos.Offset(
    this.mouse_offset.X,this.mouse_offset.Y-SystemInformation.CaptionHeight);
                     
    this.Location = mousepos;
               }
    }
  • 相关阅读:
    cvCreateStructuringElementEx理解
    GNU_GSL相关
    粒子滤波(转)
    C++指针拷贝
    c++中的复制构造函数
    通过几道题目找自信
    C++网络编程基础
    linux system : install flash player
    ContentType一览
    O_RDWR O_CREAT等open函数标志位在哪里定义?(格式还要编译,答案在最后一段)
  • 原文地址:https://www.cnblogs.com/weiling/p/1516243.html
Copyright © 2020-2023  润新知