在VB中實(shí)現(xiàn)移動(dòng)沒有標(biāo)題欄的窗口

字號(hào):

方法一
     這種方法是在窗體的MouseDown、MouseUp和MouseMove等事件的處理過程中添加代碼,實(shí)現(xiàn)在鼠標(biāo)左鍵按下后移動(dòng)時(shí),改變窗體的Left和Top屬性,實(shí)現(xiàn)移動(dòng)無標(biāo)題欄的窗體。
    進(jìn)入VB,把窗體Form1的BorderStyle屬性設(shè)置為0-None(無標(biāo)題欄),再窗體上添加一個(gè)ButtonCommand組件,用來關(guān)閉程序。代碼如下:
    Private Type POINT
    X As Single
    Y As Single
    End Type
    Dim FormP As POINT
    '記錄窗體原始位置
    Dim MouseP As POINT
    '記錄鼠標(biāo)按下時(shí)的位置
    Dim MouseLButtonDown As Boolean
    '記錄鼠標(biāo)左鍵是否按下
    Private Sub Command1_Click()
    End '退出程序
    End Sub
    Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X As Single,Y As Single)
    FormP.X = Form1.Left
    '記下窗體原始坐標(biāo)位置
    FormP.Y = Form1.Top
    MouseP.X = X
    '記下鼠標(biāo)按下時(shí)的位置
    MouseP.Y = Y
    If Button = 1 Then
    MouseLButtonDown = True
    '鼠標(biāo)左鍵按下
    End If
    End Sub