VB.NET自定义标题栏拖动

前端之家收集整理的这篇文章主要介绍了VB.NET自定义标题栏拖动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. '首先在form里添加一个panel容器
  2. Dim x1,x2,y1,y2 As Integer
  3. '鼠标左键按下后将x1,y1赋值
  4. Private Sub Panel1_MouseDown(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlMove.MouseDown
  5. If e.Button = Windows.Forms.MouseButtons.Left Then
  6. x1 = e.X
  7. y1 = e.Y
  8. End If
  9. End Sub
  10. '拖动过程中不断对x2,y2赋值
  11. Private Sub Panel1_MouseMove(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlMove.MouseMove
  12. If e.Button = Windows.Forms.MouseButtons.Left Then
  13. x2 = e.X
  14. y2 = e.Y
  15. Me.Left = Me.Location.X + (x2 - x1)
  16. Me.Top = Me.Location.Y + (y2 - y1)
  17. End If
  18. End Sub

猜你在找的VB相关文章