2012-11-03 51 views

回答

0

我不知道是否有其他替代方案,但你可以爲WM_MOUSEDOWN創建你自己的處理程序(不要完全記住它)。然後,你要做的就是找出點擊位置和控制器之間的差異。

此外,爲了移動它,您需要處理WM_MOUSEMOVE或其他東西,用指針移動窗體。

你可以通過簡單的布爾告訴mousemove來做到這一點,如果它應該對鼠標移動做出反應。

0
  1. 選擇的MainForm
  2. 屬性窗口選擇活動並添加的MouseMove事件
  3. 驗證碼:

    public int X_cood; 
    bool Mouse_Cord_Stored = false; 
    int MainForm_Mouse_X_Coordinates; 
    int MainForm_Mouse_Y_Coordinates; 
    Point p = new Point(ActiveForm.Location.X, ActiveForm.Location.Y); 
    
    private void MainForm_MouseMove(object sender, MouseEventArgs e) 
    { 
        switch (e.Button) 
        { 
         case (MouseButtons.Left)://To Let user move the Form1 when Left mouse button is pressed 
          { 
           switch (Mouse_Cord_Stored) 
           { 
            case false: 
             { 
              //If Mouse Coordinates are not stored, then store them. 
              MainForm_Mouse_X_Coordinates = e.X; 
              MainForm_Mouse_Y_Coordinates= e.Y; 
              Mouse_Cord_Stored = true; 
              break; 
             } 
            case true: 
             { 
              //Move the Form using ActiveForm.Location if mouse coordinates are stored 
              Form1.ActiveForm.Location = new Point(Form1.ActiveForm.Location.X + e.X - MainForm_Mouse_X_Coordinates 
                         , Form1.ActiveForm.Location.Y + e.Y - MainForm_Mouse_Y_Coordinates); 
              break; 
             } 
           } 
           break; 
          } 
    
         default: 
          { 
           switch (Mouse_Cord_Stored) 
           { 
            case true: 
             { 
              Mouse_Cord_Stored = false; 
              break; 
             } 
           } 
           break; 
          } 
        }