Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.BackColor = Color.DarkGray Dim PictureBox1 As New PictureBox PictureBox1.Location = New Point(10, 10) PictureBox1.Size = New Size(300, 400) PictureBox1.BackColor = Color.White Me.Controls.Add(PictureBox1) Dim PictureBox2 As New PictureBox PictureBox2.Location = New Point(320, 10) PictureBox2.Size = New Size(300, 400) PictureBox2.BackColor = Color.White Me.Controls.Add(PictureBox2) Dim font As New Font(Me.Font.FontFamily, 16) Dim Label1 As New DraggableLabel Label1.Text = "明るい性格である" Label1.Location = New Point(20, 20) Label1.Size = New Size(250, 30) Label1.BackColor = Color.Yellow Label1.Font = font Me.Controls.Add(Label1) Label1.BringToFront() Dim Label2 As New DraggableLabel Label2.Text = "真面目な性格である" Label2.Location = New Point(20, 60) Label2.Size = New Size(250, 30) Label2.BackColor = Color.Yellow Label2.Font = font Me.Controls.Add(Label2) Label2.BringToFront() Dim Label3 As New DraggableLabel Label3.Text = "優しい性格である" Label3.Location = New Point(20, 100) Label3.Size = New Size(250, 30) Label3.BackColor = Color.Yellow Label3.Font = font Me.Controls.Add(Label3) Label3.BringToFront() End Sub Public Class DraggableLabel Inherits Label Dim IsDragging As Boolean 'ドラッグ中の場合True Dim DiffPoint As Point 'ドラッグ開始地点とドラッグ開始時のボタンの位置とのずれ Private Sub Label_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown If e.Button = MouseButtons.Left Then IsDragging = True DiffPoint = New Point(e.X, e.Y) End If End Sub Private Sub Label_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp If e.Button = MouseButtons.Left Then IsDragging = False End If End Sub Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove If IsDragging Then Dim DestX As Integer = sender.Location.X + e.X - DiffPoint.X Dim DestY As Integer = sender.Location.Y + e.Y - DiffPoint.Y sender.Location = New Point(DestX, DestY) End If End Sub End Class End Class