日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#鼠標(biāo)位置相關(guān)獲取程序代碼介紹

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

企業(yè)建站必須是能夠以充分展現(xiàn)企業(yè)形象為主要目的,是企業(yè)文化與產(chǎn)品對外擴(kuò)展宣傳的重要窗口,一個合格的網(wǎng)站不僅僅能為公司帶來巨大的互聯(lián)網(wǎng)上的收集和信息發(fā)布平臺,成都創(chuàng)新互聯(lián)面向各種領(lǐng)域:成都橡塑保溫成都網(wǎng)站設(shè)計、網(wǎng)絡(luò)營銷推廣解決方案、網(wǎng)站設(shè)計等建站排名服務(wù)。


 
 
 
  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.  //以下是上述畫皮膚方法的具體實現(xiàn)部分,舉一個畫左邊框的代碼示例,   
  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)移動 ,以及反應(yīng)代碼

 
 
 
  1. //定義了一個抽象的基類MouseAction,用來表示所有的鼠標(biāo)事件,它有一個抽象方法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)拖動   
  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)拖動同樣也很簡單,不過卻稍不同于窗口的縮放拉伸,這里舉出它的實現(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.  //接下來我們開始編寫發(fā)出事件的代碼,先定義幾個變量:   
  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)的臨時坐標(biāo)   
  46.  private MouseAction mouse;//鼠標(biāo)的事件響應(yīng)對象   
  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)對象:   
  53. ///   
  54.  //鼠標(biāo)點擊左上邊框   
  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)點擊系統(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)實際上是在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í)行時間響應(yīng)   
  74.   //注意坐標(biāo)是Control.MousePosition這個靜態(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. //防止窗體被縮小成一個點,***給窗口的MinimumSize賦上一個適當(dāng)?shù)闹?,例?00,200   
  26. }  

本文名稱:C#鼠標(biāo)位置相關(guān)獲取程序代碼介紹
網(wǎng)頁鏈接:http://www.dlmjj.cn/article/dhiheso.html