zoukankan      html  css  js  c++  java
  • 窗口拖动功能,以及拖动时卡的解决方案

    const int WM_NCLBUTTONDOWN = 0xA1;  
    const int HT_CAPTION = 0x2;  
    [DllImport("user32.dll")]  
    static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);  
      
    private void Form2_MouseDown(object sender, MouseEventArgs e)  
    {  
        if (e.Button == MouseButtons.Left & this.WindowState == FormWindowState.Normal)  
        {  
            // 移动窗体   
            this.Capture = false;  
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);  
        }  
    }  
    const int WM_NCLBUTTONDOWN = 0xA1;
    const int HT_CAPTION = 0x2;
    [DllImport("user32.dll")]
    static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    
    private void Form2_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left & this.WindowState == FormWindowState.Normal)
        {
            // 移动窗体
            this.Capture = false;
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }
    }
    
    
    
     
    
    

    实验证明这个方法是比较好的,它模拟了点击窗口标题栏进行拖动的动作 

    我以前用过的方法是设置窗体的Location的方法,很卡,而且快速拖动会不同步

     
    Point m_oldpoint;  
    bool m_mouse_is_down = false;  
      
    private void pictureBox_title_MouseDown(object sender, MouseEventArgs e)  
    {  
        m_oldpoint = MousePosition;  
    }  
      
    private void pictureBox_title_MouseMove(object sender, MouseEventArgs e)  
    {  
        if ((e.Button != MouseButtons.Left) || (MousePosition == m_oldpoint))  
        {  
            return;  
        }  
        this.Location = new Point(this.Location.X + MousePosition.X - m_oldpoint.X, this.Location.Y + MousePosition.Y - m_oldpoint.Y);  
        m_oldpoint = MousePosition;  
    }  

  • 相关阅读:
    HBuilder在线打包ipa步骤
    SWD烧录/仿真方式
    详解shell脚本括号区别--$()、$「 」、$「 」 、$(()) 、「 」 、「[ 」]
    Centos/Linux下调整分区大小(以home和根分区为例)
    Centos6.5安装中文支持和中文输入法
    如何用电路实现检测过零点?这个简单电路就能搞定
    ifconfig无输出的原因及解决办法
    Linux云服务器下Tomcat部署
    linux wget 命令用法详解(附实例说明)
    yum的repo文件详解、以及epel简介、yum源的更换
  • 原文地址:https://www.cnblogs.com/diulela/p/2544593.html
Copyright © 2011-2022 走看看