winform --无边框窗体 --窗体移动API
无边框窗体:
就是吧窗体的边框去掉,然后自己做按钮设置功能。
---移入变色
1 //鼠标移入变色 2 private void pictureBox2_MouseEnter(object sender, EventArgs e) 3 { 4 //pictureBox2.BackColor = Color.Red; 5 pictureBox2.Image = Image.FromFile("G:\\0425\\6、WinForm\\2016-7-4\\Buttons\\btn_close_highlight.png"); 6 } 7 8 //鼠标按下变色 9 private void pictureBox2_MouseDown(object sender, MouseEventArgs e) 10 { 11 //pictureBox2.BackColor = Color.Navy; 12 pictureBox2.Image = Image.FromFile("G:\\0425\\6、WinForm\\2016-7-4\\Buttons\\btn_close_down.png"); 13 } 14 //鼠标移出变色 15 private void pictureBox2_MouseLeave(object sender, EventArgs e) 16 { 17 //pictureBox2.BackColor = Color.Transparent; 18 pictureBox2.Image = Image.FromFile("G:\\0425\\6、WinForm\\2016-7-4\\Buttons\\btn_close_disable.png"); 19 } 20 //点击事件 21 private void pictureBox2_Click(object sender, EventArgs e) 22 { 23 MessageBoxButtons mb = MessageBoxButtons.OKCancel; 24 DialogResult dr = MessageBox.Show("是否退出?", "退出", mb); 25 if (dr == DialogResult.OK) 26 { 27 this.Close(); 28 } 29 30 }
无边框窗体的移动:
将下面代码直接复制粘贴,将窗体的鼠标按下事件的方法改成下面方法的名字就可以直接使用
1 //窗体移动API 2 [DllImport("user32.dll")] 3 public static extern bool ReleaseCapture(); 4 [DllImport("user32.dll")] 5 public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam); 6 public const int WM_SYSCOMMAND = 0x0112; 7 public const int SC_MOVE = 0xF010; 8 public const int HTCAPTION = 0x0002; 9 [DllImport("user32")] 10 private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam); 11 private const int WM_SETREDRAW = 0xB; 12 13 private void Form1_MouseDown(object sender, MouseEventArgs e) 14 { 15 if (this.WindowState == FormWindowState.Normal) 16 { 17 ReleaseCapture(); 18 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); 19 } 20 }