当把一个窗体的borderstyle设为0-none,还有什么办法在程序运行的时候拖动窗体

解决方案 »

  1.   

    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        ReleaseCapture
        SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    End Sub
      

  2.   

    Option Explicit
    Const HTCAPTION = 2
    Const WM_NCLBUTTONDOWN = &HA1
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then '×¢ÊÍ£º Checking for Left Button only
    Dim ReturnVal As Long
    X = ReleaseCapture()
    ReturnVal = SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
    End IfEnd Sub
      

  3.   

    '不用API拖动窗体的方法:
    dim mX as long
    dim mY as longPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)   '对象移动前的对象位置和鼠标位置相关值。
       If Button = vbLeftButton Then
          MousePointer = vbSizeAll
          mX = X
          mY = Y
       End IfEnd SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Dim H As Long
       Dim V As Long
       
       On Error Resume Next
       
       If (Button = vbLeftButton) And (me.WindowState = 0) Then
       
          If (X = mY) And (Y = mY) Then Exit Sub
          
          H = Me.Left + X - mX
          V = Me.Top + Y - mY
          
          If H <= 0 Then
             H = 0
          ElseIf H >= (Screen.Width - Me.Width) Then
             H = Screen.Width - Me.Width
          End If
               
          If V <= 0 Then
             V = 0
          ElseIf V >= (Screen.Height - Me.Height) Then
             V = Screen.Height - Me.Height
          End If      Me.Move H, V   End IfEnd SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
       
       If MousePointer = vbSizeAll Then
          MousePointer = vbDefault
          Exit Sub
       End If   '如有右键菜单,在这里弹出右键菜单。
       If (Button = vbRightButton) Then
          Call PopupMenu(mnuRight)
       End IfEnd Sub
      

  4.   

    进阶问题
    当borderstyle设为0-none的时候,可不可以同样在任务条出现程序标题