自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#鼠標(biāo)位置相關(guān)獲取程序代碼介紹

開(kāi)發(fā) 后端
本文是對(duì)C#鼠標(biāo)位置相關(guān)獲取程序代碼的介紹,將從代碼談起,通過(guò)實(shí)例代碼,幫助大家對(duì)C#鼠標(biāo)位置的控制更深入的了解。

這里將介紹C#鼠標(biāo)位置相關(guān)獲取程序代碼,包括從圖片的劃分,左右邊框的確定,鼠標(biāo)移動(dòng)的控制,鼠標(biāo)手勢(shì)的控制等等。對(duì)于標(biāo)題欄雙擊***化的功能,也是重要的實(shí)現(xiàn)。

  1. // Mouse Position Operation   
  2. //Code Technology Document   
  3. //NITI Collection   
  4. //圖片的劃分   
  5. //Bottom_Left   
  6. //Bottom_Middle   
  7. //Bottom_Right   
  8. //   
  9. //Middle_Left左邊框   
  10. //Middle_Right右邊框   
  11. //標(biāo)題欄   
  12. //Top_Left   
  13. //Top_Middle   
  14. //Top_Right   
  15. //系統(tǒng)按鈕   
  16. //SysButton_Min   
  17. //SysButton_Max   
  18. //SysButton_Close   
  19. //SysButton_Restore   
  20. namespace mouse   
  21. {   
  22.  //以下是上述畫(huà)皮膚方法的具體實(shí)現(xiàn)部分,舉一個(gè)畫(huà)左邊框的代碼示例,   
  23.  private void DrawMiddle_Left(Graphics g)   
  24.  {   
  25.   Brush brush = new TextureBrush(Middle_Left, new Rectangle(0, 0,Middle_Left.Width, Middle_Left.Height));   
  26.   g.FillRectangle(brush, 0, TITLE_WIDTH, Middle_Left.Width,Height - Bottom_Middle.Height - TITLE_WIDTH);   
  27.  }  

C#鼠標(biāo)位置之鼠標(biāo)移動(dòng) ,以及反應(yīng)代碼 

  1. //定義了一個(gè)抽象的基類(lèi)MouseAction,用來(lái)表示所有的鼠標(biāo)事件,它有一個(gè)抽象方法Action:   
  2.  public abstract class MouseAction   
  3.  {   
  4.   public abstract void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form);   
  5.  }   
  6.     
  7.  //向右拉伸窗口事件的代碼響應(yīng)   
  8. // MouseSizeLeft:拉伸左邊框   
  9. // MouseSizeBottom:拉伸下邊框   
  10. // MouseSizeTop:拉伸上邊框   
  11. // MouseSizeTopLeft:拉伸左上角   
  12. // MouseSizeTopRight:拉伸右上角   
  13. // MouseSizeBottomLeft:拉伸左下角   
  14. // MouseSizeBottomRight:拉伸右下角   
  15. // MouseDrag:鼠標(biāo)拖動(dòng)   
  16.  public class MouseSizeRight : MouseAction   
  17.  {   
  18.   private int lx;   
  19.   public MouseSizeRight(int LocationX)   
  20.   {   
  21.    lx = LocationX;   
  22.   }   
  23.   public override void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form)   
  24.   {   
  25.    form.Width = ScreenX - lx;   
  26.    form.Invalidate();   
  27.   }   
  28.  }   
  29. // 鼠標(biāo)拖動(dòng)同樣也很簡(jiǎn)單,不過(guò)卻稍不同于窗口的縮放拉伸,這里舉出它的實(shí)現(xiàn)代碼:   
  30.  public class MouseDrag : MouseAction   
  31.  {   
  32.   private int x, y;   
  33.   public MouseDrag(int hitX, int hitY)   
  34.   {   
  35.    x = hitX;   
  36.    y = hitY;   
  37.   }   
  38.   public override void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form)   
  39.   {   
  40.    form.Location = new Point(ScreenX - x, ScreenY - y); [Page]  
  41.   }   
  42.  }   
  43.  //接下來(lái)我們開(kāi)始編寫(xiě)發(fā)出事件的代碼,先定義幾個(gè)變量:   
  44.  private int LEFT = 5, RIGHT = 5, BOTTOM = 5, TOP = 5, TITLE_WIDTH = 45;//邊框和標(biāo)題欄的大小   
  45.  private int x = 0, y = 0;//保存鼠標(biāo)的臨時(shí)坐標(biāo)   
  46.  private MouseAction mouse;//鼠標(biāo)的事件響應(yīng)對(duì)象   
  47.  然后在Form的MouseDown事件中記錄下鼠標(biāo)的當(dāng)前坐標(biāo):   
  48.  x = e.X;   
  49.  y = e.Y;   
  50.  附:e為System.Windows.Forms.MouseEventArgs   
  51. //////////   
  52. ///根據(jù)鼠標(biāo)的坐標(biāo)定義出事件響應(yīng)對(duì)象:   
  53. ///   
  54.  //鼠標(biāo)點(diǎn)擊左上邊框   
  55.  if((e.X <= LEFT + 10 && e.Y <= TOP) || (e.Y <= TOP + 10 && e.X <= LEFT))   
  56.  {   
  57.  mouse = new MouseSizeTopLeft(Location.X, Location.Y, Width, Height);   
  58.  return;   
  59.  }   
  60.  //鼠標(biāo)點(diǎn)擊系統(tǒng)關(guān)閉按紐   
  61.  if(e.X > Width - 20 && e.Y > 6 && e.X < Width - 20 + SysButton_Min.Width && e.Y < 6 + SysButton_Min.Height)   
  62.  {   
  63.  Close();   
  64.  return;   
  65.  }   
  66.  
  67.  //大部分的事件響應(yīng)實(shí)際上是在MouseMove事件中完成的:   
  68.  private void Form_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)   
  69.  {   
  70.   this.Parent.Cursor = CheckCursorType(e.X, e.Y);//改變鼠標(biāo)的指針形狀   
  71.   if(mouse != null)   
  72.   {   
  73.   mouse.Action(Control.MousePosition.X, Control.MousePosition.Y, this);//執(zhí)行時(shí)間響應(yīng)   
  74.   //注意坐標(biāo)是Control.MousePosition這個(gè)靜態(tài)變量給出的,它的值為鼠標(biāo)在桌面上的全局坐標(biāo)   
  75.   }   
  76.  }  

***,C#鼠標(biāo)位置MouseUp事件中將mouse變量釋放掉:

  1.  private void Form_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)   
  2. {   
  3.  mouse = null;   
  4. }   
  5. 加上標(biāo)題欄的雙擊***化或者還原的事件:  
  6.  private void Form_DoubleClick(object sender, System.EventArgs e)   
  7.  {   
  8.    if(y > TOP && y < TITLE_WIDTH)   
  9.    {   
  10.     if(WindowState == FormWindowState.Normal)   
  11.     {   
  12.      WindowState = FormWindowState.Maximized;   
  13.      SysButton = SysButton_Restore; [Page]  
  14.      Invalidate();   
  15.     }   
  16.     else if(WindowState == FormWindowState.Maximized)   
  17.     {   
  18.      WindowState = FormWindowState.Normal;   
  19.      SysButton = SysButton_Max;   
  20.      Invalidate();   
  21.     }   
  22.    }   
  23.  }   
  24.     
  25. //防止窗體被縮小成一個(gè)點(diǎn),***給窗口的MinimumSize賦上一個(gè)適當(dāng)?shù)闹?,例?00,200   
  26. }  

【編輯推薦】

  1. 如何初始化數(shù)組詳解
  2. C#數(shù)組操作的體會(huì)淺談
  3. C#關(guān)機(jī)代碼實(shí)例詳解
  4. C#關(guān)機(jī)代碼的實(shí)現(xiàn)淺析
  5. C#程序設(shè)計(jì)關(guān)閉Windows窗體淺析
責(zé)任編輯:彭凡 來(lái)源: 中國(guó)自學(xué)編程網(wǎng)
相關(guān)推薦

2009-09-07 18:41:18

2009-08-24 18:06:36

源程序代碼C#讀取XML文件

2009-08-28 16:03:15

C#程序?qū)崿F(xiàn)鼠標(biāo)移動(dòng)

2010-03-23 14:12:43

Python開(kāi)發(fā)Win

2009-09-02 19:11:42

C#鼠標(biāo)滾輪

2009-08-05 18:28:05

C#異常處理

2009-08-13 17:36:54

編譯C#代碼

2009-09-01 15:08:07

C#命名規(guī)范

2010-01-15 10:48:29

C++程序代碼

2009-09-02 14:06:14

C#文件傳送

2010-07-17 00:55:48

PHP Telnet

2010-03-29 17:37:17

Nginx resin

2010-01-15 18:46:08

C++程序代碼

2011-11-09 13:59:27

代碼腐爛

2013-07-29 14:28:43

JQueryJQuery實(shí)現(xiàn)分頁(yè)分頁(yè)程序代碼

2009-09-01 15:25:01

C#位域

2011-11-03 15:44:10

程序員

2010-07-13 09:29:37

socketUDP協(xié)議

2009-08-14 13:52:18

C#判斷數(shù)據(jù)類(lèi)型

2009-08-12 18:35:36

C# ArrayLis
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)