用鼠标按住form的某个部分,然后拖动窗体移动到某个区域。

解决方案 »

  1.   

    Option Explicit
    'Variables
    'Switch to turn drah on and off.
    Dim MoveScreen As Boolean
    'Vars to get the mouse position on the form.
    '   you are draging.
    Dim MousX As Integer
    Dim MousY As Integer
    'Vars for moving the form.
    Dim CurrX As Integer
    Dim CurrY As IntegerPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MoveScreen = True ' make form movable while the mouse is down.
        'Get the initial coordinates of the mouse on the form.
        MousX = X
        MousY = Y
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
           
        'If the mouse is down on the form then.
        If MoveScreen Then
            'Calculate the new x,y position for the form.
            '   NB. This is dependant on the X and Y vars on the Form_MouseMove,
            '   you can use objects MouseMove function. i.e. a Label or Textbox.
            CurrX = Form1.Left - MousX + X
            CurrY = Form1.Top - MousY + Y
            'Move the form to the new X,Y.
            Form1.Move CurrX, CurrY     ' move form.
        End If
        
     
    End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MoveScreen = False    ' stop the form from moving.
    End Sub
      

  2.   

    楼上的代码怎么那么多?
    不就是一个窗口拖吗?看下面的代码:
    '******************************************
    Option Explicit
    Dim bDrag As Boolean
    Dim sngCX As Single, sngCY As SinglePrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       bDrag = True: sngCX = X: sngCY = Y
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       If bDrag Then Left = Left + X - sngCX: Top = Top + Y - sngCY
    End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
       bDrag = False
    End Sub
    '********************************************
      

  3.   

    多谢各位了,我已经用api做出来了