zoukankan      html  css  js  c++  java
  • 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;
               }
    }
  • 相关阅读:
    try catch 和\或 finally 的用法
    postgresql与oracle对比
    今天遇到个let: not found
    NTLM相关
    【搜藏】net use命令拓展
    【shell进阶】字符串操作
    【网摘】网上邻居用户密码
    测试导航
    关系代数合并数据 left join
    真正的程序员
  • 原文地址:https://www.cnblogs.com/weiling/p/1516243.html
Copyright © 2011-2022 走看看