justanotheruser
justanotheruser

Reputation: 23

Copy to clipboard through builtin windows function, not sefmade subroutine

I want to add a “COPY” button to my application and I should to enumerate a lot of controls for it:

If TypeOf activeControl Is TextBox Then ...
ElseIf TypeOf activeControl Is RichTextBox Then ...
ElseIf TypeOf activeControl Is DataGridView Then ...
ElseIf TypeOf activeControl Is WebBrowser Then ...

etc.

But at the same time builtin copy command, activated by CTRL+C, works well and copy plain text from textbox and richtextbox, table from DGV and, say, HTML table as table, not as "BODY-TABLE-BLABLABLA".

So, my question: is it possible to activate that sort of copy to clipboard (may be simulate CTRL+C pressing?) when my button is pressed?

Code like

Private Sub copy_button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles copy_button.Click
     SendKeys.Send("^C")
End sub

is not works. Thanks.

Upvotes: 0

Views: 2391

Answers (1)

Riv
Riv

Reputation: 1859

For windows forms, you can use the clipboard class System.Windows.Forms.Clipboard

Clipboard.SetText(YourText)

More information: http://msdn.microsoft.com/en-us/library/637ys738.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

Upvotes: 2

Related Questions