winform 无边框窗口

(1)无边框窗口的拖动事件

新建一个MenuStrip,然后注册其MouseMove与MouseDown事件

private Point formPoint = new Point();public MainForm() { InitializeComponent();}private void MenuStrip_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point myPosition = MousePosition; myPosition.Offset(-formPoint.X, -formPoint.Y); Location = myPosition; }}private void MenuStrip_MouseDown(object sender, MouseEventArgs e) { formPoint.X = e.X; formPoint.Y = e.Y;}

(2)无边框窗口的关闭事件

 

相关文章