Imports System.ComponentModel
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.IO
public class LabelDragDrop
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Private Sub Label5_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label5.MouseDown
Label5.DoDragDrop(Label5, DragDropEffects.Copy)
End Sub
Private Sub Label6_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label6.MouseDown
Label6.DoDragDrop(Label6, DragDropEffects.Copy)
End Sub
Private Sub Label7_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label7.MouseDown
Label7.DoDragDrop(Label7.Text, DragDropEffects.Copy)
End Sub
Private Sub Label8_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label8.MouseDown
Label8.DoDragDrop(Label8.Text, DragDropEffects.Copy)
End Sub
Private Sub Label9_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Label9.DragEnter
If e.Data.GetDataPresent(GetType(System.Windows.Forms.Label)) Then
e.Effect = DragDropEffects.Copy
Label9.BorderStyle = BorderStyle.FixedSingle
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub Label9_DragLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.DragLeave
Label9.BorderStyle = BorderStyle.Fixed3D
End Sub
Private Sub Label9_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Label9.DragDrop
Dim lbl As Label = DirectCast( _
e.Data.GetData(GetType(Label)), Label)
Label9.Text = lbl.Text
Label9.BackColor = lbl.BackColor
Label9.BorderStyle = BorderStyle.Fixed3D
End Sub
Private Sub Label10_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Label10.DragEnter
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub Label10_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Label10.DragDrop
Label10.Text = e.Data.GetData(DataFormats.Text).ToString
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.Label9 = New System.Windows.Forms.Label
Me.Label10 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(29, 20)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(83, 12)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label Sources"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(221, 20)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(77, 12)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Text Sources"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(29, 145)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(77, 12)
Me.Label3.TabIndex = 2
Me.Label3.Text = "Label Target"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(221, 145)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(71, 12)
Me.Label4.TabIndex = 3
Me.Label4.Text = "Text Target"
'
'Label5
'
Me.Label5.BackColor = System.Drawing.Color.Blue
Me.Label5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label5.Location = New System.Drawing.Point(35, 43)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(100, 23)
Me.Label5.TabIndex = 4
'
'Label6
'
Me.Label6.BackColor = System.Drawing.Color.Red
Me.Label6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label6.Location = New System.Drawing.Point(35, 77)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(100, 23)
Me.Label6.TabIndex = 5
'
'Label7
'
Me.Label7.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label7.Location = New System.Drawing.Point(229, 47)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(100, 23)
Me.Label7.TabIndex = 6
Me.Label7.Text = "Hello"
'
'Label8
'
Me.Label8.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label8.Location = New System.Drawing.Point(229, 77)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(100, 23)
Me.Label8.TabIndex = 7
Me.Label8.Text = "Hi"
'
'Label9
'
Me.Label9.AllowDrop = True
Me.Label9.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label9.Location = New System.Drawing.Point(35, 170)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(100, 23)
Me.Label9.TabIndex = 8
'
'Label10
'
Me.Label10.AllowDrop = True
Me.Label10.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label10.Location = New System.Drawing.Point(229, 170)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(100, 23)
Me.Label10.TabIndex = 9
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(373, 217)
Me.Controls.Add(Me.Label10)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents Label10 As System.Windows.Forms.Label
End Class