Public Class Form1 ' マウスが押された時の各Labelの座標 Private dictMovedPoints As Dictionary(Of Label, Point) Private dictFlgMouseDowns As Dictionary(Of Label, Boolean) Sub New() ' この呼び出しはデザイナーで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後で初期化を追加します。 Me.dictMovedPoints = New Dictionary(Of Label, Point) Me.dictFlgMouseDowns = New Dictionary(Of Label, Boolean) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' ラベル Dim lbls As Label() = {Me.Label1, Me.Label2, Me.Label3} For Each lbl As Label In lbls lbl.Text = lbl.Name lbl.Font = New System.Drawing.Font("MS UI Gothic", 18.0!, System.Drawing.FontStyle.Regular, _ System.Drawing.GraphicsUnit.Point, CType(128, Byte)) lbl.BorderStyle = BorderStyle.FixedSingle Next End Sub ' LabelのMouseDownイベントを共通で行う。 Private Sub LabelMouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles Label1.MouseDown, Label2.MouseDown, Label3.MouseDown ' 対象のラベル Dim lbl As Label = DirectCast(sender, Label) Me.dictFlgMouseDowns(lbl) = True Me.dictMovedPoints(lbl) = e.Location End Sub Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles Label1.MouseUp, Label2.MouseUp, Label3.MouseUp Dim lbl As Label = DirectCast(sender, Label) Me.dictFlgMouseDowns(lbl) = False 'Console.WriteLine("MouseUp") End Sub ' LabelのMouseMoveイベントを共通で行う。 Private Sub LabelMouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles Label1.MouseMove, Label2.MouseMove, Label3.MouseMove ' 対象のラベル Dim lbl As Label = DirectCast(sender, Label) If Not Me.dictFlgMouseDowns.ContainsKey(lbl) Then Return End If Dim flgMouseDown = Me.dictFlgMouseDowns(lbl) If Not flgMouseDown Then Return End If Dim labelPoint As Point = Me.dictMovedPoints(lbl) Dim p As Point = Me.Label1.Parent.PointToClient(Cursor.Position) lbl.Location = New Point(p.X - labelPoint.X, p.Y - labelPoint.Y) lbl.Text = lbl.Location.ToString() End Sub End Class