C# WinForm自定义拖动窗体
??????? private bool isMouseDown = false;
??????? private Point FormLocation;???? //form的location
??????? private Point mouseOffset;????? //鼠標的按下位置
??????? private void pnlTitle_MouseDown(object sender, MouseEventArgs e)
??????? {
??????????? if (e.Button == MouseButtons.Left)
??????????? {
??????????????? isMouseDown = true;
??????????????? FormLocation = this.Location;
??????????????? mouseOffset = Control.MousePosition;
??????????? }
??????? }
??????? private void pnlTitle_MouseUp(object sender, MouseEventArgs e)
??????? {
??????????? isMouseDown = false;
??????? }
??????? private void pnlTitle_MouseMove(object sender, MouseEventArgs e)
??????? {
??????????? int _x = 0;
??????????? int _y = 0;
??????????? if (isMouseDown)
??????????? {
??????????????? Point pt = Control.MousePosition;
??????????????? _x = mouseOffset.X - pt.X;
??????????????? _y = mouseOffset.Y - pt.Y;
??????????????? this.Location = new Point(FormLocation.X - _x, FormLocation.Y - _y);
??????????? }
??????? }
轉載于:https://www.cnblogs.com/whz881027/articles/2106296.html
總結
以上是生活随笔為你收集整理的C# WinForm自定义拖动窗体的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UnisGuard防篡改产品了解
- 下一篇: 亲爱的你在哪里