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;
               }
    }
  • 相关阅读:
    【转】SMARTY 不乱码截取中文
    godaddy最新优惠码
    javascript 学习之屏幕尺寸获取。
    IE6 实现minwidth
    css 修改页面选中时背景颜色
    jQuery 闪动的文字提示
    jQuery插件 blockUI
    HTML 5 video 视频标签全属性详解
    linux打包压缩命令汇总
    Windows 下MySQL zip 安装
  • 原文地址:https://www.cnblogs.com/weiling/p/1516243.html
Copyright © 2011-2022 走看看