Copy Link Shortcut In Web Browser

Azreal

Member
Joined
Oct 4, 2006
Messages
19
Programming Experience
Beginner
Hello, I have added my own context menu to a web browser control and I was wondering if and how I would be able to add text to the clipboard from a link in the web browser control. Kind of like the IE Copy Shortcut.
This is how I copy text:

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] docx [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] HtmlDocument = wb1.Document[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] readme [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'assume user has made selection and clicked a toolbar button[/COLOR][/SIZE]
[SIZE=2]docx.ExecCommand([/SIZE][SIZE=2][COLOR=#800000]"copy"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2], readme)[/SIZE]
 
Last edited:
Using contextmenu also activates the element, this works:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] href [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = wb.Document.ActiveElement.GetAttribute([/SIZE][SIZE=2][COLOR=#800000]"href"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] href <> [/SIZE][SIZE=2][COLOR=#800000]"" [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] My[/COLOR][/SIZE][SIZE=2].Computer.Clipboard.SetText(href)[/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] My[/COLOR][/SIZE][SIZE=2].Computer.Clipboard.Clear()[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
 
Back
Top