'Du behöver en bild som heter headpic.
' Formens variabler
Dim OldX As Short
Dim OldY As Short
Private Sub HeadPic_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles HeadPic.MouseMove
If e.Button = MouseButtons.Left Then
Dim PointX As Short, PointY As Short ' Skapar variabler.
PointX = Me.Left + e.X ' PointX ställs in på X-värdet av musen (av hela skärmen).
PointY = Me.Top + e.Y ' PointY ställs in på Y-värdet av musen (av hela skärmen).
If PointX < 15 + OldX Then
Me.Left = 0
ElseIf PointX >= Screen.PrimaryScreen.WorkingArea.Width + OldX - Me.Width - 15 Then
Me.Left = Screen.PrimaryScreen.WorkingArea.Width - Me.Width
Else
Me.Left = Me.Left + (e.X - OldX)
End If
If PointY <= 15 + OldY Then
Me.Top = 0
ElseIf PointY >= Screen.PrimaryScreen.WorkingArea.Height + OldY - Me.Width - 15 Then
Me.Top = Screen.PrimaryScreen.WorkingArea.Height - Me.Height
Else
Me.Top = Me.Top + (e.Y - OldY)
End If
End If
End Sub
Private Sub HeadPic_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles HeadPic.MouseDown
OldX = e.X
OldY = e.Y
End Sub