Use ClipBoard to copy Object : Clipboard « Windows System « 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 » Windows System » ClipboardScreenshots 
Use ClipBoard to copy Object
Use ClipBoard to copy Object

Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.IO
Imports System.Xml.Serialization

Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim myform As New Form1()
        Application.Run(myform)            

    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

    ' Copy the Student to the clipboard.
    Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnCopy.Click
        Dim emp As New Student(txtFirstName.Text, txtLastName.Text)
        Dim data_object As New DataObject
        data_object.SetData("Student", emp)
        Clipboard.SetDataObject(data_object)
    End Sub

    ' Paste data from the clipboard.
    Private Sub btnPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnPaste.Click
        Dim data_object As IDataObject = Clipboard.GetDataObject()
        If data_object.GetDataPresent("Student"Then
            Dim emp As Student = DirectCast(data_object.GetData("Student"), Student)
            txtPasteFirstName.Text = emp.FirstName
            txtPasteLastName.Text = emp.LastName
        End If
    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.btnPaste = New System.Windows.Forms.Button
        Me.txtPasteLastName = New System.Windows.Forms.TextBox
        Me.txtPasteFirstName = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.btnCopy = 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.SuspendLayout()
        '
        'btnPaste
        '
        Me.btnPaste.Location = New System.Drawing.Point(23296)
        Me.btnPaste.Name = "btnPaste"
        Me.btnPaste.Size = New System.Drawing.Size(4824)
        Me.btnPaste.TabIndex = 22
        Me.btnPaste.Text = "Paste"
        '
        'txtPasteLastName
        '
        Me.txtPasteLastName.Location = New System.Drawing.Point(72112)
        Me.txtPasteLastName.Name = "txtPasteLastName"
        Me.txtPasteLastName.Size = New System.Drawing.Size(13620)
        Me.txtPasteLastName.TabIndex = 21
        '
        'txtPasteFirstName
        '
        Me.txtPasteFirstName.Location = New System.Drawing.Point(7288)
        Me.txtPasteFirstName.Name = "txtPasteFirstName"
        Me.txtPasteFirstName.Size = New System.Drawing.Size(13620)
        Me.txtPasteFirstName.TabIndex = 20
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(8112)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(5413)
        Me.Label3.TabIndex = 19
        Me.Label3.Text = "Last Name"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(888)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(5313)
        Me.Label4.TabIndex = 18
        Me.Label4.Text = "First Name"
        '
        'btnCopy
        '
        Me.btnCopy.Location = New System.Drawing.Point(23216)
        Me.btnCopy.Name = "btnCopy"
        Me.btnCopy.Size = New System.Drawing.Size(4824)
        Me.btnCopy.TabIndex = 17
        Me.btnCopy.Text = "Copy"
        '
        'txtLastName
        '
        Me.txtLastName.Location = New System.Drawing.Point(7232)
        Me.txtLastName.Name = "txtLastName"
        Me.txtLastName.Size = New System.Drawing.Size(13620)
        Me.txtLastName.TabIndex = 16
        Me.txtLastName.Text = "Last Name"
        '
        'txtFirstName
        '
        Me.txtFirstName.Location = New System.Drawing.Point(728)
        Me.txtFirstName.Name = "txtFirstName"
        Me.txtFirstName.Size = New System.Drawing.Size(13620)
        Me.txtFirstName.TabIndex = 15
        Me.txtFirstName.Text = "First Name"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(832)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(5413)
        Me.Label2.TabIndex = 14
        Me.Label2.Text = "Last Name"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(88)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(5313)
        Me.Label1.TabIndex = 13
        Me.Label1.Text = "First Name"
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(288139)
        Me.Controls.Add(Me.btnPaste)
        Me.Controls.Add(Me.txtPasteLastName)
        Me.Controls.Add(Me.txtPasteFirstName)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.btnCopy)
        Me.Controls.Add(Me.txtLastName)
        Me.Controls.Add(Me.txtFirstName)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Form1"
        Me.Text = "CopyPasteStudent"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents btnPaste As System.Windows.Forms.Button
    Friend WithEvents txtPasteLastName As System.Windows.Forms.TextBox
    Friend WithEvents txtPasteFirstName As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents btnCopy 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

End Class

           
       
Related examples in the same category
1.Get File Name List from clipboard
2.Copy Data from RichTextBox to the clipboardCopy Data from RichTextBox to the clipboard
3.Paste Data from clipboard to a Label using DataFormats.RtfPaste Data from clipboard to a Label using DataFormats.Rtf
4.Paste Data from clipboard to a RichTextBox using DataFormats.TextPaste Data from clipboard to a RichTextBox using DataFormats.Text
5.Paste Data from clipboard to a Label using DataFormats.HtmlPaste Data from clipboard to a Label using DataFormats.Html
6.Copy Rtf format data from RichTextBox into clipboardCopy Rtf format data from RichTextBox into clipboard
7.Copy Plain Text format data from RichTextBox into clipboardCopy Plain Text format data from RichTextBox into clipboard
8.Copy HTML format data from RichTextBox into clipboardCopy HTML format data from RichTextBox into clipboard
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.