zoukankan      html  css  js  c++  java
  • Winform无标题窗体移动方法

    需添加using System.Runtime.InteropServices

     

    /*=================================================================*/

    函数功能:该函数从当前线程中的窗口释放鼠标捕获,并恢复通常的鼠标输入处理。捕获鼠标的窗口接收所有的鼠标输入(无论光标的位置在哪里),除非点击鼠标键时,光标热点在另一个线程的窗口中。

      函数原型:BOOL ReleaseCaptureVOlD

      参数:无。

      返回值:如果函数调用成功,返回非零值;如果函数调用失败,返回值是零。若想获得更多的错误信息,请调用GetlastError函数。

      备注:应用程序在调用函数SetCaPture之后调用此函数。

    Windows 95:调用ReleaseCapture会引起失去鼠标捕获的窗日接收一个WM_CAPTURECHANGED消息

    /*=================================================================*/

     

    //窗体移动属性

    [DllImport("user32.dll")]         

    public static extern bool ReleaseCapture();

     

    //发送消息

    [DllImport("user32.dll")]

    public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

     

    //属性

    public const int WM_SYSCOMMAND = 0x0112;

    public const int SC_MOVE = 0xF010;

    public const int HTCAPTION = 0x0002;

    在窗体的MouseDown事件中,调用以上二个方法,如下:

    #region 窗体移动事件

    /// <summary>

    /// 窗体移动事件

    /// </summary>

    private void Login_MouseDown(object sender, MouseEventArgs e)

    {

         if (e.Button == MouseButtons.Left)//只有左键才能移动

         {

              if (e.Y < 30)//只有最上面那行才能实现移动

              {

                  ReleaseCapture();//捕获鼠标

                  //发送消息

                  SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);

          }

    }

    #endregion

  • 相关阅读:
    C#磁吸屏幕窗体类库
    准备
    我写的诗
    How to turn off a laptop keyboard
    How to tell which commit a tag points to in Git?
    Why should I care about lightweight vs. annotated tags?
    How to get rid of “would clobber existing tag”
    Facebook, Google and Twitter threaten to leave Hong Kong over privacy law changes
    The need for legislative reform on secrecy orders
    Can a foreign key be NULL and/or duplicate?
  • 原文地址:https://www.cnblogs.com/chhuic/p/1813383.html
Copyright © 2011-2022 走看看