VB.Net Tutorial/GUI/Label Drag Drop

Материал из VB Эксперт
Перейти к: навигация, поиск

Drag and drop color between label

Imports System.ruponentModel
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.rupilerServices.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.ruponentModel.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

Drag and drop custom object

Imports System.Data
Imports System.Data.OleDb
Imports System.Xml.Serialization
Imports System.IO
Imports System.Windows.Forms
public class DragEmployee2
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    <Serializable()> _
    Public Class Employee
        Public FirstName As String
        Public LastName As String
        Public Sub New()
        End Sub
        Public Sub New(ByVal first_name As String, ByVal last_name As String)
            FirstName = first_name
            LastName = last_name
        End Sub
    End Class
    Private Sub lblDragSource_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblDragSource.MouseDown
        Dim emp As New Employee(txtFirstName.Text, txtLastName.Text)
        Dim data_object As New DataObject()
        data_object.SetData("Employee", emp)
        If lblDragSource.DoDragDrop(data_object, _
            DragDropEffects.Copy Or DragDropEffects.Move) = DragDropEffects.Move _
        Then
            txtFirstName.Text = ""
            txtLastName.Text = ""
        End If
    End Sub
    Private Sub lblDropTarget_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragOver
        If e.Data.GetDataPresent("Employee") Then
            Const KEY_CTRL As Integer = 8
            If (e.KeyState And KEY_CTRL) <> 0 Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.Move
            End If
        End If
    End Sub
    Private Sub lblDropTarget_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragDrop
        Dim emp As Employee = DirectCast(e.Data.GetData("Employee"), Employee)
        lblFirstName.Text = emp.FirstName
        lblLastName.Text = emp.LastName
    End Sub
    Private Sub btnShowSerialization_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowSerialization.Click
        Dim emp As New Employee(txtFirstName.Text, txtLastName.Text)
        Dim string_writer As New StringWriter()
        Dim serializer As New XmlSerializer(GetType(Employee))
        serializer.Serialize(string_writer, emp)
        Console.WriteLine(string_writer.ToString)
    End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads 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.ruponentModel.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.lblLastName = New System.Windows.Forms.Label
        Me.lblFirstName = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.btnShowSerialization = New System.Windows.Forms.Button
        Me.txtLastName = New System.Windows.Forms.TextBox
        Me.txtFirstName = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.lblDropTarget = New System.Windows.Forms.Label
        Me.lblDragSource = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "lblLastName
        "
        Me.lblLastName.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblLastName.Location = New System.Drawing.Point(288, 104)
        Me.lblLastName.Name = "lblLastName"
        Me.lblLastName.Size = New System.Drawing.Size(136, 20)
        Me.lblLastName.TabIndex = 28
        Me.lblLastName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        "
        "lblFirstName
        "
        Me.lblFirstName.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblFirstName.Location = New System.Drawing.Point(288, 80)
        Me.lblFirstName.Name = "lblFirstName"
        Me.lblFirstName.Size = New System.Drawing.Size(136, 20)
        Me.lblFirstName.TabIndex = 27
        Me.lblFirstName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        "
        "Label3
        "
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(224, 104)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(54, 13)
        Me.Label3.TabIndex = 26
        Me.Label3.Text = "Last Name"
        "
        "Label4
        "
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(224, 80)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(53, 13)
        Me.Label4.TabIndex = 25
        Me.Label4.Text = "First Name"
        "
        "btnShowSerialization
        "
        Me.btnShowSerialization.Location = New System.Drawing.Point(56, 136)
        Me.btnShowSerialization.Name = "btnShowSerialization"
        Me.btnShowSerialization.Size = New System.Drawing.Size(104, 24)
        Me.btnShowSerialization.TabIndex = 24
        Me.btnShowSerialization.Text = "Show Serialization"
        "
        "txtLastName
        "
        Me.txtLastName.Location = New System.Drawing.Point(72, 104)
        Me.txtLastName.Name = "txtLastName"
        Me.txtLastName.Size = New System.Drawing.Size(136, 20)
        Me.txtLastName.TabIndex = 23
        Me.txtLastName.Text = "S"
        "
        "txtFirstName
        "
        Me.txtFirstName.Location = New System.Drawing.Point(72, 80)
        Me.txtFirstName.Name = "txtFirstName"
        Me.txtFirstName.Size = New System.Drawing.Size(136, 20)
        Me.txtFirstName.TabIndex = 22
        Me.txtFirstName.Text = "R"
        "
        "Label2
        "
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(8, 104)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 13)
        Me.Label2.TabIndex = 21
        Me.Label2.Text = "Last Name"
        "
        "Label1
        "
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(8, 80)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(53, 13)
        Me.Label1.TabIndex = 20
        Me.Label1.Text = "First Name"
        "
        "lblDropTarget
        "
        Me.lblDropTarget.AllowDrop = True
        Me.lblDropTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDropTarget.Location = New System.Drawing.Point(224, 8)
        Me.lblDropTarget.Name = "lblDropTarget"
        Me.lblDropTarget.Size = New System.Drawing.Size(200, 64)
        Me.lblDropTarget.TabIndex = 19
        Me.lblDropTarget.Text = "Drop Target"
        "
        "lblDragSource
        "
        Me.lblDragSource.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDragSource.Location = New System.Drawing.Point(8, 8)
        Me.lblDragSource.Name = "lblDragSource"
        Me.lblDragSource.Size = New System.Drawing.Size(200, 64)
        Me.lblDragSource.TabIndex = 18
        Me.lblDragSource.Text = "Drag Source"
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(433, 177)
        Me.Controls.Add(Me.lblLastName)
        Me.Controls.Add(Me.lblFirstName)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.btnShowSerialization)
        Me.Controls.Add(Me.txtLastName)
        Me.Controls.Add(Me.txtFirstName)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.lblDropTarget)
        Me.Controls.Add(Me.lblDragSource)
        Me.Name = "Form1"
        Me.Text = "DragEmployee2"
        Me.ResumeLayout(False)
        Me.PerformLayout()
    End Sub
    Friend WithEvents lblLastName As System.Windows.Forms.Label
    Friend WithEvents lblFirstName As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents btnShowSerialization As System.Windows.Forms.Button
    Friend WithEvents txtLastName As System.Windows.Forms.TextBox
    Friend WithEvents txtFirstName As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents lblDropTarget As System.Windows.Forms.Label
    Friend WithEvents lblDragSource As System.Windows.Forms.Label
End Class

Drag and drop text between labels

Imports System.ruponentModel
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.rupilerServices.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.ruponentModel.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

Label drag

Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
public class LabelDrag
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    " Start a drag.
    Private Sub lblDragSource_MouseDown(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblDragSource.MouseDown
        lblDragSource.DoDragDrop("Here"s the drag data!", DragDropEffects.Copy)
    End Sub
    " Make sure the drag is coming from lblDragSource.
    Private Sub lblDropTarget_DragEnter(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.DragEventArgs) _
     Handles lblDropTarget.DragEnter
        e.Effect = DragDropEffects.Copy
    End Sub
    " Display the dropped data.
    Private Sub lblDropTarget_DragDrop(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.DragEventArgs) _
     Handles lblDropTarget.DragDrop
        MessageBox.Show(e.Data.GetData("Text").ToString)
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads 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.ruponentModel.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.lblDragSource = New System.Windows.Forms.Label
        Me.lblDropTarget = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "lblDragSource
        "
        Me.lblDragSource.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDragSource.Location = New System.Drawing.Point(16, 16)
        Me.lblDragSource.Name = "lblDragSource"
        Me.lblDragSource.Size = New System.Drawing.Size(96, 64)
        Me.lblDragSource.TabIndex = 0
        Me.lblDragSource.Text = "Drag Source"
        Me.lblDragSource.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "lblDropTarget
        "
        Me.lblDropTarget.AllowDrop = True
        Me.lblDropTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDropTarget.Location = New System.Drawing.Point(168, 16)
        Me.lblDropTarget.Name = "lblDropTarget"
        Me.lblDropTarget.Size = New System.Drawing.Size(96, 64)
        Me.lblDropTarget.TabIndex = 1
        Me.lblDropTarget.Text = "Drop Target"
        Me.lblDropTarget.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(279, 95)
        Me.Controls.Add(Me.lblDropTarget)
        Me.Controls.Add(Me.lblDragSource)
        Me.Name = "Form1"
        Me.Text = "LabelDrag"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents lblDragSource As System.Windows.Forms.Label
    Friend WithEvents lblDropTarget As System.Windows.Forms.Label
End Class

Label Drag and Drop

Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
public class DragWithApp
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private m_Dragging As Boolean
    Private Sub lblDragSource_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblDragSource.MouseDown
        m_Dragging = True
        lblDragSource.DoDragDrop("Some text", DragDropEffects.Copy)
        m_Dragging = False
    End Sub
    Private Sub lblDropTarget_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragEnter
        If m_Dragging Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub
    Private Sub lblDropTarget_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragDrop
        MessageBox.Show(e.Data.GetData(DataFormats.Text).ToString)
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads 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.ruponentModel.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.lblDropTarget = New System.Windows.Forms.Label
        Me.lblDragSource = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "lblDropTarget
        "
        Me.lblDropTarget.AllowDrop = True
        Me.lblDropTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDropTarget.Location = New System.Drawing.Point(160, 8)
        Me.lblDropTarget.Name = "lblDropTarget"
        Me.lblDropTarget.Size = New System.Drawing.Size(120, 96)
        Me.lblDropTarget.TabIndex = 3
        Me.lblDropTarget.Text = "Drop Target"
        Me.lblDropTarget.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "lblDragSource
        "
        Me.lblDragSource.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDragSource.Location = New System.Drawing.Point(8, 8)
        Me.lblDragSource.Name = "lblDragSource"
        Me.lblDragSource.Size = New System.Drawing.Size(120, 96)
        Me.lblDragSource.TabIndex = 2
        Me.lblDragSource.Text = "Drag Source"
        Me.lblDragSource.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(288, 114)
        Me.Controls.Add(Me.lblDropTarget)
        Me.Controls.Add(Me.lblDragSource)
        Me.Name = "Form1"
        Me.Text = "DragWithinApp"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents lblDropTarget As System.Windows.Forms.Label
    Friend WithEvents lblDragSource As System.Windows.Forms.Label
End Class

Label Drop

Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
public class LabelDrag2
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private Sub lblDragSource_MouseDown(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblDragSource.MouseDown
        lblDragSource.DoDragDrop("Here"s the drag data!", DragDropEffects.Copy)
    End Sub
    Private Sub lblDropTarget_DragEnter(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragEnter
        If e.Data.GetDataPresent("Text") Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub
    Private Sub lblDropTarget_DragDrop(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.DragEventArgs) _
     Handles lblDropTarget.DragDrop
        MessageBox.Show(e.Data.GetData("Text").ToString)
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads 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.ruponentModel.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.lblDropTarget = New System.Windows.Forms.Label
        Me.lblDragSource = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "lblDropTarget
        "
        Me.lblDropTarget.AllowDrop = True
        Me.lblDropTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDropTarget.Location = New System.Drawing.Point(168, 16)
        Me.lblDropTarget.Name = "lblDropTarget"
        Me.lblDropTarget.Size = New System.Drawing.Size(96, 64)
        Me.lblDropTarget.TabIndex = 3
        Me.lblDropTarget.Text = "Drop Target"
        Me.lblDropTarget.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "lblDragSource
        "
        Me.lblDragSource.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDragSource.Location = New System.Drawing.Point(16, 16)
        Me.lblDragSource.Name = "lblDragSource"
        Me.lblDragSource.Size = New System.Drawing.Size(96, 64)
        Me.lblDragSource.TabIndex = 2
        Me.lblDragSource.Text = "Drag Source"
        Me.lblDragSource.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(279, 95)
        Me.Controls.Add(Me.lblDropTarget)
        Me.Controls.Add(Me.lblDragSource)
        Me.Name = "Form1"
        Me.Text = "LabelDrag2"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents lblDropTarget As System.Windows.Forms.Label
    Friend WithEvents lblDragSource As System.Windows.Forms.Label
End Class