欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)隨鼠標(biāo)移動(dòng)窗體實(shí)例

 更新時(shí)間:2014年10月11日 09:08:06   投稿:shichen2014  
這篇文章主要介紹了C#實(shí)現(xiàn)隨鼠標(biāo)移動(dòng)窗體實(shí)例,主要通過(guò)簡(jiǎn)單的窗體事件代碼即可實(shí)現(xiàn)鼠標(biāo)隨窗體移動(dòng)的功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了c#實(shí)現(xiàn)隨鼠標(biāo)移動(dòng)窗體的方法,分享給大家供大家參考。

具體實(shí)現(xiàn)方法如下:

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; 
  } 
} 

如果窗體有標(biāo)題則改為:

Top -= SystemInformation.CaptionHeight;

如果有邊框則改為:

Top -= SystemInformation.FormBorderSize.Height
Left -= SystemInformation.FormBorderSize.Width

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助

相關(guān)文章

最新評(píng)論