Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 26-02-2009
Join Date: Jan 2009
Posts: 36
How to use windows clipboard to copy text in a vb.net application?


How to use windows clipboard to copy text in a vb.net application?

Please provide me an example!
Reply With Quote
Old 26-02-2009
Join Date: Jan 2009
Posts: 9
Re: How to use windows clipboard to copy text in a vb.net application?

I think you need to study this!


I hope this helps!
Reply With Quote
Old 26-02-2009
Join Date: Jan 2009
Posts: 44
Re: How to use windows clipboard to copy text in a vb.net application?

In this first instalment of a four-part series of articles on programmatically transferring data to and from the Windows Clipboard, I'll explain the basic steps of using the Clipboard using the Clipboard API. After I've gone over the basics steps, which are used no matter what data format is on the Clipboard, I'll present a demo application that illustrates how to programmatically transfer simple (ANSI) text to and from the Clipboard.

Using the Windows Clipboard API
Reply With Quote
Old 26-02-2009
Join Date: May 2008
Posts: 26
Re: How to use windows clipboard to copy text in a vb.net application?

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()

    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.EventArgs) Handles btnCopy.Click
        Dim emp As New Student(txtFirstName.Text, txtLastName.Text)
        Dim data_object As New DataObject
        data_object.SetData("Student", emp)
    End Sub

    ' Paste data from the clipboard.
    Private Sub btnPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 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
        End If
    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.btnPaste.Location = New System.Drawing.Point(232, 96)
        Me.btnPaste.Name = "btnPaste"
        Me.btnPaste.Size = New System.Drawing.Size(48, 24)
        Me.btnPaste.TabIndex = 22
        Me.btnPaste.Text = "Paste"
        Me.txtPasteLastName.Location = New System.Drawing.Point(72, 112)
        Me.txtPasteLastName.Name = "txtPasteLastName"
        Me.txtPasteLastName.Size = New System.Drawing.Size(136, 20)
        Me.txtPasteLastName.TabIndex = 21
        Me.txtPasteFirstName.Location = New System.Drawing.Point(72, 88)
        Me.txtPasteFirstName.Name = "txtPasteFirstName"
        Me.txtPasteFirstName.Size = New System.Drawing.Size(136, 20)
        Me.txtPasteFirstName.TabIndex = 20
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(8, 112)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(54, 13)
        Me.Label3.TabIndex = 19
        Me.Label3.Text = "Last Name"
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(8, 88)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(53, 13)
        Me.Label4.TabIndex = 18
        Me.Label4.Text = "First Name"
        Me.btnCopy.Location = New System.Drawing.Point(232, 16)
        Me.btnCopy.Name = "btnCopy"
        Me.btnCopy.Size = New System.Drawing.Size(48, 24)
        Me.btnCopy.TabIndex = 17
        Me.btnCopy.Text = "Copy"
        Me.txtLastName.Location = New System.Drawing.Point(72, 32)
        Me.txtLastName.Name = "txtLastName"
        Me.txtLastName.Size = New System.Drawing.Size(136, 20)
        Me.txtLastName.TabIndex = 16
        Me.txtLastName.Text = "Last Name"
        Me.txtFirstName.Location = New System.Drawing.Point(72, 8)
        Me.txtFirstName.Name = "txtFirstName"
        Me.txtFirstName.Size = New System.Drawing.Size(136, 20)
        Me.txtFirstName.TabIndex = 15
        Me.txtFirstName.Text = "First Name"
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(8, 32)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 13)
        Me.Label2.TabIndex = 14
        Me.Label2.Text = "Last Name"
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(53, 13)
        Me.Label1.TabIndex = 13
        Me.Label1.Text = "First Name"
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(288, 139)
        Me.Name = "Form1"
        Me.Text = "CopyPasteStudent"

    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
Reply With Quote
Old 03-04-2009
Join Date: Apr 2009
Posts: 1
Re: How to use windows clipboard to copy text in a vb.net application?

Jesus ppl,

why does everyone have to take a simple questions and do this kind of c**p. Just give him a simple answer and stop trying to "show off" or whatever you all are doing.

Clipboard.SetText("Your text to set to the clipboard")
dim sClipboard as string = Clipboard.GetText 'This gets text on clipboard and assigns it to sClipboard.
Reply With Quote

  TechArena Community > Software > Software Development
Tags: ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "How to use windows clipboard to copy text in a vb.net application?"
Thread Thread Starter Forum Replies Last Post
Windows 7: ctrl+C cannot copy onto the clipboard The!Winston Operating Systems 5 02-12-2010 07:44 AM
Not able to Copy in Clipboard using VBScript Pratim Software Development 5 27-01-2010 07:34 PM
How to Copy to Clipboard automatically while selecting text in Firefox? Henryosa Technology & Internet 4 21-01-2010 07:16 PM
Code to copy to clipboard Brunoz Software Development 3 24-11-2009 01:42 PM
Copy the path of a File/Folder to Clipboard in WIndows 7 & Vista TheGreatOne Tips & Tweaks 2 21-03-2009 07:08 PM

All times are GMT +5.5. The time now is 05:40 PM.