skwerm
asked on
Clipboard Problems in VB.Net
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(se nder 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(st rX)
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!
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(se
'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(st
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
Is there another class in your project named Clipboard? maybe theres a naming conflict?
ASKER
That was it!
Many, many thanks!
Many, many thanks!
If txtText.SelectedText.Trim(
txtText.SelectAll()
txtText.Copy()
Else
txtText.Copy()
End If