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;
               }
    }
  • 相关阅读:
    aria2安装webui
    c++指针参数是如何传递内存的
    ssl 证书申请
    LNMP一键包安装后解决MySQL无法远程连接问题
    流水线设计 转:http://www.opengpu.org/forum.php?mod=viewthread&tid=2424
    IUS nc simulator
    ccd与coms摄像头的区别
    昨天下午写的FPGA驱动VGA显示图片
    tcl脚本
    用FPGA驱动ov7670摄像头用tft9328显示
  • 原文地址:https://www.cnblogs.com/weiling/p/1516243.html
Copyright © 2011-2022 走看看