C#完成隨鼠標挪動窗體實例。本站提示廣大學習愛好者:(C#完成隨鼠標挪動窗體實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成隨鼠標挪動窗體實例正文
本文實例講述了c#完成隨鼠標挪動窗體的辦法,分享給年夜家供年夜家參考。
詳細完成辦法以下:
private void MainForm_Load(object sender, EventArgs e) { //綁定事宜 MouseMove += Form_MouseMove; MouseDown += Form_MouseDown; } private Point _mousePoint; private void Form_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Top = MousePosition.Y - _mousePoint.Y; Left = MousePosition.X - _mousePoint.X; } } private void Form_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { _mousePoint.X = e.X; _mousePoint.Y = e.Y; } }
假如窗體有題目則改成:
Top -= SystemInformation.CaptionHeight;
假如有邊框則改成:
Top -= SystemInformation.FormBorderSize.Height Left -= SystemInformation.FormBorderSize.Width
願望本文所述對年夜家的C#法式設計有所贊助