當鼠標按下窗體時,是否有一種方法使窗體沒有邊框(FormBorderStyle設置為“None”),就像有邊框一樣?
3 回答

jeck貓
TA貢獻1909條經驗 獲得超7個贊
private bool mouseDown;private Point lastLocation; private void Form1_MouseDown(object sender, MouseEventArgs e) { mouseDown = true; lastLocation = e.Location; } private void Form1_MouseMove(object sender, MouseEventArgs e) { if(mouseDown) { this.Location = new Point( (this.Location.X - lastLocation.X) + e.X, (this.Location.Y - lastLocation.Y) + e.Y); this.Update(); } } private void Form1_MouseUp(object sender, MouseEventArgs e) { mouseDown = false; }

瀟瀟雨雨
TA貢獻1833條經驗 獲得超4個贊
public partial class Form1 : Form{ public Form1() { InitializeComponent(); // set this.FormBorderStyle to None here if needed // if set to none, make sure you have a way to close the form! } protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_NCHITTEST) m.Result = (IntPtr)(HT_CAPTION); } private const int WM_NCHITTEST = 0x84; private const int HT_CLIENT = 0x1; private const int HT_CAPTION = 0x2;}
- 3 回答
- 0 關注
- 359 瀏覽
添加回答
舉報
0/150
提交
取消