VB.NET自定义标题栏拖动

'首先在form里添加一个panel容器
   Dim x1,x2,y1,y2 As Integer
  '鼠标左键按下后将x1,y1赋值
    Private Sub Panel1_MouseDown(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlMove.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            x1 = e.X
            y1 = e.Y
        End If
    End Sub
  '拖动过程中不断对x2,y2赋值
    Private Sub Panel1_MouseMove(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlMove.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            x2 = e.X
            y2 = e.Y
            Me.Left = Me.Location.X + (x2 - x1)  
            Me.Top = Me.Location.Y + (y2 - y1)         
        End If
    End Sub

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...