C
Cor Ligthert
Hi Sameh,
I made today this sample for John Crouse, do you think you can do something
with it?
Cor
\\\
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Private WithEvents Label1 As New System.Windows.Forms.Label
Private WithEvents Label2 As New System.Windows.Forms.Label
Private mouseX, mouseY As Integer
Private arLabels() As Label
Dim myMousedown As String
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ClientSize = New System.Drawing.Size(400, 400)
Label1.Name = "Label1"
Label2.Name = "Label2"
arLabels = New Label() {Label1, Label2}
Dim lblY As Integer = 100
For Each Lbl As Label In arLabels
Lbl.Location = New System.Drawing.Point(100, lblY)
Lbl.ForeColor = Color.Red
Lbl.BackColor = Color.Transparent
Lbl.TextAlign = ContentAlignment.MiddleCenter
Lbl.Text = Lbl.Location.X.ToString & "." &
Lbl.Location.Y.ToString
AddHandler Lbl.MouseDown, AddressOf Label_MouseDown
AddHandler Lbl.MouseUp, AddressOf Label_MouseUp
AddHandler Lbl.MouseMove, AddressOf Label_MouseMove
lblY += 30
Me.Controls.Add(Lbl)
Next
End Sub
Private Sub Label_MouseDown(ByVal sender As Object, ByVal _
e As System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
myMousedown = lbl.Name
lbl.BringToFront()
mouseX = Cursor.Position.X - lbl.Location.X
mouseY = Cursor.Position.Y - lbl.Location.Y
lbl.Cursor = Cursors.Hand
End Sub
Private Sub Label_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
myMousedown = ""
lbl.Cursor = Cursors.Default
End Sub
Private Sub Label_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Position.X,
Cursor.Position.Y)
If Point.op_Inequality(NowCursor, LastCursor) Then
If myMousedown = lbl.Name Then
lbl.Location = New System.Drawing.Point(Cursor.Position.X _
- mouseX, Cursor.Position.Y - mouseY)
End If
LastCursor = Cursor.Position
lbl.Text = lbl.Location.X.ToString & "." &
lbl.Location.Y.ToString
End If
End Sub
End Class
///
I made today this sample for John Crouse, do you think you can do something
with it?
Cor
\\\
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Private WithEvents Label1 As New System.Windows.Forms.Label
Private WithEvents Label2 As New System.Windows.Forms.Label
Private mouseX, mouseY As Integer
Private arLabels() As Label
Dim myMousedown As String
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ClientSize = New System.Drawing.Size(400, 400)
Label1.Name = "Label1"
Label2.Name = "Label2"
arLabels = New Label() {Label1, Label2}
Dim lblY As Integer = 100
For Each Lbl As Label In arLabels
Lbl.Location = New System.Drawing.Point(100, lblY)
Lbl.ForeColor = Color.Red
Lbl.BackColor = Color.Transparent
Lbl.TextAlign = ContentAlignment.MiddleCenter
Lbl.Text = Lbl.Location.X.ToString & "." &
Lbl.Location.Y.ToString
AddHandler Lbl.MouseDown, AddressOf Label_MouseDown
AddHandler Lbl.MouseUp, AddressOf Label_MouseUp
AddHandler Lbl.MouseMove, AddressOf Label_MouseMove
lblY += 30
Me.Controls.Add(Lbl)
Next
End Sub
Private Sub Label_MouseDown(ByVal sender As Object, ByVal _
e As System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
myMousedown = lbl.Name
lbl.BringToFront()
mouseX = Cursor.Position.X - lbl.Location.X
mouseY = Cursor.Position.Y - lbl.Location.Y
lbl.Cursor = Cursors.Hand
End Sub
Private Sub Label_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
myMousedown = ""
lbl.Cursor = Cursors.Default
End Sub
Private Sub Label_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Position.X,
Cursor.Position.Y)
If Point.op_Inequality(NowCursor, LastCursor) Then
If myMousedown = lbl.Name Then
lbl.Location = New System.Drawing.Point(Cursor.Position.X _
- mouseX, Cursor.Position.Y - mouseY)
End If
LastCursor = Cursor.Position
lbl.Text = lbl.Location.X.ToString & "." &
lbl.Location.Y.ToString
End If
End Sub
End Class
///