這個功能在VB中需要借助於API函數才能實現而在中憑自己的功能就能實現首先設置窗體的FormBorderStyle屬性為none以去掉窗體的邊框然後在窗體上添加一個按鈕窗體中的代碼如下
Public Class Form
Inherits System<a _blank>Windows</a>FormsForm
Private mouse_offset As Point
Private Sub form_MouseDown(ByVal sender As Object _
ByVal e As SystemWindowsFormsMouseEventArgs) Handles MyBaseMouseDown
mouse_offset = New Point(eX eY)
End Sub
Private Sub form_MouseMove(ByVal Sender As SystemObject _
ByVal e As SystemWindowsFormsMouseEventArgs) Handles MyBaseMouseMove
按住鼠標左右鍵均可拖動窗體
If eButton = MouseButtonsLeft Or eButton = MouseButtonsRight Then
Dim mousePos As Point = Senderfindform()MousePosition
獲得鼠標偏移量
mousePosOffset(mouse_offsetX mouse_offsetY)
設置窗體隨鼠標一起移動
Senderfindform()Location = mousePos
End If
End Sub
Private Sub BtnExit_Click(ByVal sender As SystemObject _
ByVal e As SystemEventArgs) Handles ButtonClick
關閉窗體
MeClose()
End Sub
End Class
From:http://tw.wingwit.com/Article/program/net/201311/12947.html