Tree drag and drop to a TextBox : Drag Drop « GUI « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » GUI » Drag DropScreenshots 
Tree drag and drop to a TextBox

Imports System
Imports System.Drawing
Imports System.Reflection
Imports System.Windows.Forms

public class MainClass

   Shared Sub Main()
      Dim form1 As Form = New Form1
      Application.Run(form1)
   End Sub

End Class





Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        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.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents DestinationTextBox As System.Windows.Forms.TextBox
    Friend WithEvents SourceTextBox As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.DestinationTextBox = New System.Windows.Forms.TextBox()
        Me.SourceTextBox = New System.Windows.Forms.TextBox()
        Me.ListBox1 = New System.Windows.Forms.ListBox()
        Me.TreeView1 = New System.Windows.Forms.TreeView()
        Me.SuspendLayout()
        '
        'DestinationTextBox
        '
        Me.DestinationTextBox.AllowDrop = True
        Me.DestinationTextBox.Font = New System.Drawing.Font("Verdana"9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.DestinationTextBox.Location = New System.Drawing.Point(4166)
        Me.DestinationTextBox.Multiline = True
        Me.DestinationTextBox.Name = "DestinationTextBox"
        Me.DestinationTextBox.Size = New System.Drawing.Size(354195)
        Me.DestinationTextBox.TabIndex = 1
        Me.DestinationTextBox.Text = ""
        '
        'SourceTextBox
        '
        Me.SourceTextBox.Font = New System.Drawing.Font("Verdana"9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.SourceTextBox.Location = New System.Drawing.Point(44)
        Me.SourceTextBox.Multiline = True
        Me.SourceTextBox.Name = "SourceTextBox"
        Me.SourceTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.SourceTextBox.Size = New System.Drawing.Size(354144)
        Me.SourceTextBox.TabIndex = 2
        Me.SourceTextBox.Text = "Use your right or left key to drag and drop item in left ListBox or Tree to the bottom TextBox."
        '
        'ListBox1
        '
        Me.ListBox1.Font = New System.Drawing.Font("Verdana"9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ListBox1.ItemHeight = 14
        Me.ListBox1.Items.AddRange(New Object() {"Item 1""Item 2""Item 3""Item 4""Item 5""Item 6""Item 7""Item 8""Item 9""Item 10""Item 11""Item 12""Item 13""Item 14""Item 15"})
        Me.ListBox1.Location = New System.Drawing.Point(3704)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
        Me.ListBox1.Size = New System.Drawing.Size(190144)
        Me.ListBox1.TabIndex = 3
        '
        'TreeView1
        '
        Me.TreeView1.Font = New System.Drawing.Font("Verdana"9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TreeView1.ImageIndex = -1
        Me.TreeView1.Location = New System.Drawing.Point(370166)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node0", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node1"), New System.Windows.Forms.TreeNode("Node12", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node13")}), New System.Windows.Forms.TreeNode("Node14"), New System.Windows.Forms.TreeNode("Node15", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node16"), New System.Windows.Forms.TreeNode("Node17")})}), New System.Windows.Forms.TreeNode("Node2", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node3", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node4"), New System.Windows.Forms.TreeNode("Node5"), New System.Windows.Forms.TreeNode("Node6")}), New System.Windows.Forms.TreeNode("Node7"), New System.Windows.Forms.TreeNode("Node8", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node10"), New System.Windows.Forms.TreeNode("Node11")}), New System.Windows.Forms.TreeNode("Node9")})})
        Me.TreeView1.SelectedImageIndex = -1
        Me.TreeView1.Size = New System.Drawing.Size(187195)
        Me.TreeView1.TabIndex = 4
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.AutoScroll = True
        Me.ClientSize = New System.Drawing.Size(564367)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TreeView1, Me.ListBox1, Me.SourceTextBox, Me.DestinationTextBox})
        Me.Name = "Form1"
        Me.Text = "Drag and Drop Demo"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub Destination_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgsHandles DestinationTextBox.DragDrop
        DestinationTextBox.Text = e.Data.GetData(DataFormats.Text).ToString
        DestinationTextBox.BackColor = Color.White
    End Sub

    Private Sub Destination_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgsHandles DestinationTextBox.DragEnter
        DestinationTextBox.BackColor = Color.Yellow
        e.Effect = DragDropEffects.Copy
    End Sub

    Private Sub SourceTextBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgsHandles SourceTextBox.MouseDown
        SourceTextBox.DoDragDrop(SourceTextBox.SelectedText, DragDropEffects.Copy Or DragDropEffects.Move)
    End Sub

    Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgsHandles ListBox1.MouseDown
        Dim As Integer, selItems As String
        For i = To ListBox1.SelectedItems.Count - 1
            selItems = selItems & ListBox1.SelectedItems.Item(i& vbCrLf
        Next
        SourceTextBox.DoDragDrop(selItems, DragDropEffects.Copy Or DragDropEffects.Move)
    End Sub

    Private Sub Destination_DragLeave(ByVal sender As System.Object, ByVal e As System.EventArgsHandles DestinationTextBox.DragLeave
        DestinationTextBox.BackColor = Color.White
    End Sub

    Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgsHandles TreeView1.MouseDown
        If e.Button = MouseButtons.Right Then
            TreeView1.DoDragDrop(TreeView1.SelectedNode.Text, DragDropEffects.Copy Or DragDropEffects.Move)
        End If
    End Sub
End Class

           
       
Related examples in the same category
1.ListBox drag and drop to a TextBoxListBox drag and drop to a TextBox
2.Drag and drop serialized Object base on XMLDrag and drop serialized Object base on XML
3.Drag and drop TreeViewDrag and drop TreeView
4.Drag and drop between two ListBoxDrag and drop between two ListBox
5.Drag and drop between Two RichTextBoxDrag and drop between Two RichTextBox
6.Simple Drag and Drop Event IllustrationSimple Drag and Drop Event Illustration
7.Drag and Drop between LabelsDrag and Drop between Labels
8.Make sure the drop data is TextMake sure the drop data is Text
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.