28-04-20, 12:27 AM
كود :
Public m_wirdowstae As FormWindowState = FormWindowState.Normal
Public m_Mousepressed As Boolean = False
Public m_oldx As Integer, m_oldy As Integer
Private Sub ct1_mousedoun(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim ts As Point = Me.PointToScreen(e.Location)
m_oldx = ts.X
m_oldy = ts.Y
m_Mousepressed = True
End Sub
Private Sub ct1_mouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
m_Mousepressed = False
End Sub
Private Sub ct1_mousemove(ByVal sender As Object, ByVal e As MouseEventArgs)
If m_Mousepressed = True AndAlso m_wirdowstae <> FormWindowState.Minimized Then
Dim ts As Point = Me.PointToScreen(e.Location)
Me.Location = New Point(Me.Location.X + (ts.X - m_oldx), Me.Location.Y + (ts.Y - m_oldy))
m_oldx = ts.X
m_oldy = ts.Y
End If
End Sub
Sub New()
InitializeComponent()
AddHandler Me.MouseDown, New MouseEventHandler(AddressOf ct1_mousedoun)
AddHandler Me.MouseMove, New MouseEventHandler(AddressOf ct1_mousemove)
AddHandler Me.MouseUp, New MouseEventHandler(AddressOf ct1_mouseUp)
End Sub