Solved

Clipboard Problems in VB.Net

Posted on 2006-10-20
5
404 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 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