C#拖动自己的标题栏(panel)以及实现窗体三态

 

//实现拖动

1.在窗体类里面加入,下面两个,按提示加入命名空间

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern bool ReleaseCapture();

2.拖动一个panel然后,闪电事件中加入下面代码,实现拖动
private void panel1_MouseDown(object sender, MouseEventArgs e)//在panel1中添加mouse_down事件
{
  const int WM_NCLBUTTONDOWN = 0x00A1;
  const int HTCAPTION = 2;

  if (e.Button == MouseButtons.Left) // 按下的是鼠标左键
  {
    ReleaseCapture();
    SendMessage(this.Handle, WM_NCLBUTTONDOWN, (IntPtr)HTCAPTION, IntPtr.Zero); // 拖动窗体
  }
}

//三态实现

C#拖动自己的标题栏(panel)以及实现窗体三态

上一篇:WIndows Server Backup 安装


下一篇:chrome浏览器的JSON格式化插件JSON-Handle