Solved

Clipboard Problems in VB.Net

Posted on 2006-10-20
5
402 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
Comment Utility
try using the full namespace to the Clipboard class:

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

Expert Comment

by:Ravi Singh
Comment Utility
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
Comment Utility
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
Comment Utility
Is there another class in your project named Clipboard? maybe theres a naming conflict?
0
 

Author Comment

by:skwerm
Comment Utility
That was it!

Many, many thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now