Answered by:
ClipBoard is not ''detecting'' my copied text

Question
-
Hello ù|ù
I am actually trying to get the copied text which is in the clipboard...
I'm using
Dim cbtxt As String = My.Computer.Clipboard.GetText MsgBox(cbtxt)
And the messagebox is always returning blank...
Any help would be "sympatic" D:
y0ga
Monday, March 12, 2018 7:58 PM
Answers
-
Hello,
Best to try the following rather than using My namespace method.
Dim iData As IDataObject = Clipboard.GetDataObject() If iData.GetDataPresent(DataFormats.Text) Then MessageBox.Show(CType(iData.GetData(DataFormats.Text), String)) Else MessageBox.Show("Data in the clipboard is not availble as plain text") End If
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator
- Marked as answer by y0ga Tuesday, March 13, 2018 6:23 AM
Monday, March 12, 2018 9:04 PM
All replies
-
You need to test the clipboard first and determine what type of data it contains. According to these results the clipboard does not contain any text.
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Monday, March 12, 2018 8:07 PM -
Thank you for your reply ^^
I tried but it seems that it is even not recognizing the clipboard content becaus no msgbox is show
If Clipboard.ContainsText Then Dim cbtxt As String = Clipboard.GetText MsgBox(cbtxt) End If
But it is conaining something !
Monday, March 12, 2018 8:16 PM -
But it is conaining something !
But that something is not plain text. What are you copying from?
You can use the overload that takes a TextDataFormat value if you need to specify that the text is RichText or CSV or HTML or Unicode. If the clipboard data is not plain text then you can use the GetDataObject method to try to determine what is on the clipboard and convert it to some textual representation if possible.
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Edited by Reed KimbleMVP Monday, March 12, 2018 8:22 PM
Monday, March 12, 2018 8:21 PM -
I am copying the text from Ctrl/C shortcut... How should I use GetDataObject ?
Thank you a lot
Monday, March 12, 2018 8:45 PM -
I am copying the text from Ctrl/C shortcut...
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Monday, March 12, 2018 8:48 PM -
From Notepad, selecting some text and pressing ctrl+c
Thanks again
Monday, March 12, 2018 8:50 PM -
Hello,
Best to try the following rather than using My namespace method.
Dim iData As IDataObject = Clipboard.GetDataObject() If iData.GetDataPresent(DataFormats.Text) Then MessageBox.Show(CType(iData.GetData(DataFormats.Text), String)) Else MessageBox.Show("Data in the clipboard is not availble as plain text") End If
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator
- Marked as answer by y0ga Tuesday, March 13, 2018 6:23 AM
Monday, March 12, 2018 9:04 PM -
From Notepad, selecting some text and pressing ctrl+c
Thanks again
Have you tried the Unicode format option? Maybe this is something to do with non-English language?
Clipboard.GetText(TextDataFormat.UnicodeText)
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Monday, March 12, 2018 9:21 PM -
What happens if you manually paste the copied text into a TextBox for example (Control - V)? Does text get pasted?
Here's a link to the Clipboard Class which may be of assistance for checking the clipboard prior to getting text from it.
And here's a link for auto detect clipboard additions which will tell what is in the clipboard since all possibilities are listed pasting an image from clipboard into a picturebox from bitmap to wavaudio.
La vida loca
- Proposed as answer by Cor Ligthert Tuesday, March 13, 2018 12:48 AM
Monday, March 12, 2018 9:50 PM