[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Clipboard Problems in VB.Net

Posted on 2006-10-20
5
Medium Priority
?
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

650 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