Solved

Clipboard Problems in VB.Net

Posted on 2006-10-20
5
403 Views
Last Modified: 2006-11-18
Greetings!

I'm simply trying to copy/paste plain text strings from/to the clipboard. I've found some sample code on the internet (and here at EE) and it seems like it should be straight-forward. Strangely enough, my Clipboard object doesn't seem to have the methods these examples use, in particular SetDataObject() and GetDataObject().

I've got this code:

Private Sub BtnCopyToClipboardClick(sender As System.Object, e As System.EventArgs)
           'Copy the selected text to the clipboard
        Dim strX As String = txtText.SelectedText
       
        'if no text is selected, copy the entire text
        If strX.Length = 0 Then strX = txtText.Text
       
       'Copy data if any to copy
        If strX.Length > 0 Then
            Clipboard.SetDataObject(strX)
        End If


And I get this error:
  error BC30456: 'SetDataObject' is not a member of 'Clipboard'.

The only methods that show up on my clipboard object are: Equals, Finalize, GetHashCode, GetType, and ToString.

Any idea what's going on?

Thanks!

0
Comment
Question by:skwerm
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 17774633
try using the full namespace to the Clipboard class:

System.Windows.Forms.Clipboard.SetDataObject(strX)
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17774681
You can also use the Copy method on the textbox to accomplish what your after, the following will copy all the text in the textbox if none is selected else it will copy the selected text:

        If txtText.SelectedText.Trim() = String.Empty Then
            txtText.SelectAll()
            txtText.Copy()
        Else
            txtText.Copy()
        End If
0
 

Author Comment

by:skwerm
ID: 17774745
Zephyr:

When I use the entire namespace I do get the missing methods on the Clipboard object. So the problem is fixed.

Any idea why I needed the full namespec? I have "Imports System.Windows.Forms" at the top of my form's source code.

0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17774754
Is there another class in your project named Clipboard? maybe theres a naming conflict?
0
 

Author Comment

by:skwerm
ID: 17774785
That was it!

Many, many thanks!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question