Results 1 to 5 of 5

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

  1. #1
    Join Date
    Jan 2009
    Posts
    36

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

    Hi,

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

    Please provide me an example!

  2. #2
    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!

    http://msdn.microsoft.com/en-us/libr...01(VS.60).aspx

    I hope this helps!

  3. #3
    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

  4. #4
    Join Date
    May 2008
    Posts
    26

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

    Code:
    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.EventArgs) Handles 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.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
                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(232, 96)
            Me.btnPaste.Name = "btnPaste"
            Me.btnPaste.Size = New System.Drawing.Size(48, 24)
            Me.btnPaste.TabIndex = 22
            Me.btnPaste.Text = "Paste"
            '
            'txtPasteLastName
            '
            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
            '
            'txtPasteFirstName
            '
            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
            '
            'Label3
            '
            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"
            '
            'Label4
            '
            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"
            '
            'btnCopy
            '
            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"
            '
            'txtLastName
            '
            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"
            '
            'txtFirstName
            '
            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"
            '
            'Label2
            '
            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"
            '
            'Label1
            '
            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"
            '
            '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, 139)
            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

  5. #5
    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.

Similar Threads

  1. Windows 7: ctrl+C cannot copy onto the clipboard
    By The!Winston in forum Operating Systems
    Replies: 5
    Last Post: 02-12-2010, 07:44 AM
  2. Not able to Copy in Clipboard using VBScript
    By Pratim in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 07:34 PM
  3. Replies: 4
    Last Post: 21-01-2010, 07:16 PM
  4. Code to copy to clipboard
    By Brunoz in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 01:42 PM
  5. Replies: 2
    Last Post: 21-03-2009, 07:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,803,451.67698 seconds with 16 queries