Jump to content

Clipboard

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
How do I get and send text to the clipboard?

I'd like the user to press a button and then retrieve the text (if it is text) and paste it into a textbox.

#2
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
You want the System.Windows.Forms.Clipboard class. Or, if you're using VB.NET 2.0 *(or C# 2.0, and have referenced Microsoft.VisualBasic.MyServices), you can use My.Computer.Clipboard.

#3
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
Thanks!

I use


textBox1.Text = System.Windows.Forms.Clipboard.GetText();


but what if the item in the clipboard isn't text? Will I receive an exception?

#4
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts

dirkfirst said:

Thanks!

I use


textBox1.Text = System.Windows.Forms.Clipboard.GetText();


but what if the item in the clipboard isn't text? Will I receive an exception?
No, I don't believe it'll throw - I think it just returns null. Of course, you could always use the ContainsText method to check first. Or try it and see.