Pokud plovoucí po celé obrazovce, tak formulář. Pokud prvek Panel plovoucí uvnitř formuláře, tak třeba:
Public Class Form1
Private mysiPosun As Point
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Panel1.Anchor = AnchorStyles.None
Panel1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
End Sub
Private Sub Panel1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Panel1.MouseDown
mysiPosun = New Point(-e.X - Me.Left, -e.Y - Me.Top - 30)
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Panel1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim pnl As Panel = sender
Dim mousePos As Point = Control.MousePosition
mousePos.Offset(mysiPosun.X, mysiPosun.Y)
pnl.Location = mousePos
End If
End Sub
Private Sub OpravPolohuPanelu()
If Panel1.Left > Me.Width - 20 Then Panel1.Left = Me.Width - 20
If Panel1.Top > Me.Height - 50 Then Panel1.Top = Me.Height - 50
If Panel1.Left < -Panel1.Width + 10 Then Panel1.Left = -Panel1.Width + 20
If Panel1.Top < -Panel1.Height + 10 Then Panel1.Top = -Panel1.Height + 20
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Panel1.MouseUp
OpravPolohuPanelu()
End Sub
Private Sub Form1_SizeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.SizeChanged
OpravPolohuPanelu()
End Sub
End Class
S komentáři viz snippety: http://vbnet.cz/snippet--10-jak_umoznit_...
|