Drag and drop serialized Object base on XML : 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 
Drag and drop serialized Object base on XML
Drag and drop serialized Object base on XML

Imports System
Imports System.Collections
Imports System.Data
Imports System.Xml.Serialization
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Drawing.Drawing2D
Imports System.IO

Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1

        Application.Run(form1)


    End Sub
End Class



Public Class Form1
    <Serializable()> _
    Public Class Student
        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.MouseEventArgsHandles lblDragSource.MouseDown
        Dim emp As New Student(txtFirstName.Text, txtLastName.Text)
        Dim data_object As New DataObject()
        data_object.SetData("Student", 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.DragEventArgsHandles lblDropTarget.DragOver
        If e.Data.GetDataPresent("Student"Then
            Const KEY_CTRL As Integer = 8
            If (e.KeyState And KEY_CTRL<> 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.DragEventArgsHandles lblDropTarget.DragDrop
        Dim emp As Student = DirectCast(e.Data.GetData("Student"), Student)
        lblFirstName.Text = emp.FirstName
        lblLastName.Text = emp.LastName
    End Sub

    Private Sub btnShowSerialization_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnShowSerialization.Click
        Dim emp As New Student(txtFirstName.Text, txtLastName.Text)
        Dim string_writer As New StringWriter()
        Dim serializer As New XmlSerializer(GetType(Student))
        serializer.Serialize(string_writer, emp)
        MessageBox.Show(string_writer.ToString, _
            "Serialization", MessageBoxButtons.OK, _
            MessageBoxIcon.Information)
    End Sub
End Class


<Global.Microsoft.VisualBasic.CompilerServices.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.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.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(288104)
        Me.lblLastName.Name = "lblLastName"
        Me.lblLastName.Size = New System.Drawing.Size(13620)
        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(28880)
        Me.lblFirstName.Name = "lblFirstName"
        Me.lblFirstName.Size = New System.Drawing.Size(13620)
        Me.lblFirstName.TabIndex = 27
        Me.lblFirstName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(224104)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(5413)
        Me.Label3.TabIndex = 26
        Me.Label3.Text = "Last Name"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(22480)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(5313)
        Me.Label4.TabIndex = 25
        Me.Label4.Text = "First Name"
        '
        'btnShowSerialization
        '
        Me.btnShowSerialization.Location = New System.Drawing.Point(56136)
        Me.btnShowSerialization.Name = "btnShowSerialization"
        Me.btnShowSerialization.Size = New System.Drawing.Size(20024)
        Me.btnShowSerialization.TabIndex = 24
        Me.btnShowSerialization.Text = "Show Serialization"
        '
        'txtLastName
        '
        Me.txtLastName.Location = New System.Drawing.Point(72104)
        Me.txtLastName.Name = "txtLastName"
        Me.txtLastName.Size = New System.Drawing.Size(13620)
        Me.txtLastName.TabIndex = 23
        Me.txtLastName.Text = "Last Name"
        '
        'txtFirstName
        '
        Me.txtFirstName.Location = New System.Drawing.Point(7280)
        Me.txtFirstName.Name = "txtFirstName"
        Me.txtFirstName.Size = New System.Drawing.Size(13620)
        Me.txtFirstName.TabIndex = 22
        Me.txtFirstName.Text = "First Name"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(8104)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(5413)
        Me.Label2.TabIndex = 21
        Me.Label2.Text = "Last Name"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(880)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(5313)
        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(2248)
        Me.lblDropTarget.Name = "lblDropTarget"
        Me.lblDropTarget.Size = New System.Drawing.Size(20064)
        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(88)
        Me.lblDragSource.Name = "lblDragSource"
        Me.lblDragSource.Size = New System.Drawing.Size(20064)
        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(433177)
        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 = "DragStudent2"
        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

           
       
Related examples in the same category
1.Tree drag and drop to a TextBox
2.ListBox drag and drop to a TextBoxListBox drag and drop to a TextBox
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.