Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to make use of clipboard in Visual Basic.Net

Author: DevASP
Download Source Code : 352_Clipboard.zip

This article is about how to make use of the clipboard in vb.net. Whenever you cut or copy some text or an object it is copied into your clipboard from where you can access it.

  • Steps you will do. 
  • Start visual studio and create a new window application. 
  • Drop four label controls on your form and set their following properties as below:

 

First label

Text =”First Name”

 

Second label

Text =”Last Name”

 

Third label

Text =”First Name”

 

Fourth label

Text =”Last Name”

  • Drop four text box controls on the form and set their following properties as below:

 

First text box

Name = “txtFirstName”

Text = “Umar”

 

Second text box

Name = “txtLastName”

Text = “Siddique”

 

Third text box

Name = “txtDropFirstName”

Text = “”

 

Fourth text box

Name = “txtDropLastName”

Text = “”

  • Now drop two button controls on form and set their following properties as below:

 

First Button Control

Name = “btnCopy”

Text = “Copy”

 

Second Button Control

Name = “btnPaste”

Text = “Paste”

 

  • Open your code window and make a class as below.

_

 

Public Class Employee

 

   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

  • In the click event of btnCopy write the following code to copy data from clipboard.

Dim emp As New Employee(txtFirstName.Text, txtLastName.Text)

Clipboard.SetDataObject(emp)

  • In the click event of btnPaste write the following code to get and paste data from clipboard.

Dim data_object As IDataObject = Clipboard.GetDataObject

If data_object.GetDataPresent("howto_net_clipboard_object.Employee") Then

Dim emp As Employee = DirectCast(data_object.GetData("howto_net_clipboard_object.Employee"), Employee)

txtDropFirstName.Text = emp.FirstName

txtDropLastName.Text = emp.LastName

Else

txtDropFirstName.Text = ""

txtDropLastName.Text = ""

End If

 

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to open other Applications Using VB.Net Application.

Disclaimer - Privacy
© 2002-2017 DevASP.net