Hello
I made a toolbox like thing by using a panel with a label docked on top.
I can move the toolbox by dragging on the label. I've coded it, VB6 style
and got no problem. Then I tried to use new VB.NET way and now I'm stuck.
If you examine Label1_MouseMove event you'll see both methods.
Can anybody fix it?
To execute the code:
1-) Add a panel: Panel1
2-) Add a label into panel (Label1)
Then run...
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''
Public Class Form1
Private Structure MoveStructure
Public MouseOffset As Point
Public MouseDown As Boolean
End Structure
Private Move As MoveStructure
Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
Move.MouseDown = True
Move.MouseOffset = New Point(e.X, e.Y)
End Sub
Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
If Not Move.MouseDown Then Exit Sub
''New way
'Dim Dif As Point = New Point(e.X, e.Y)
'Dif.Offset(Move.MouseOffset)
'Panel1.Location = Dif
'Move.MouseOffset = Dif
'Exit Sub
'Old way
Dim DifX As Integer = Move.MouseOffset.X - e.X
Dim DifY As Integer = Move.MouseOffset.Y - e.Y
With Panel1
.Top = .Top - DifY
.Left = .Left - DifX
End With
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With Label1
.AutoSize = False
.BorderStyle = BorderStyle.FixedSingle
.BackColor = System.Drawing.SystemColors.ActiveCaption
.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
.Dock = DockStyle.Top
End With
Panel1.BorderStyle = BorderStyle.FixedSingle
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''