how do i determine highlighted text?

tahu191

Well-known member
Joined
Oct 27, 2005
Messages
48
Location
USA
Programming Experience
Beginner
i need to be able to determine what text is highlighted on a form so if the user clicks something it will import whatever is highlighted into a notepad-like program i made
 
since you're talking about highlighting text, i'm assuming you're using a Textbox or RichTextBox control

simply use the textbox's SelectedText property to get the highlighted text
 
no im not actually talking about that. I have a webBrowser and i want the user to be able to highlight text, right click and open it in a word processor i made
 
WebBrowser is an application of itself and got its own context menus, just add a button or some other user interface outside. Here is an example:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button5_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) _
[/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button5.Click
WebBrowser1.Focus()
SendKeys.SendWait([/SIZE][SIZE=2][COLOR=#800000]"^c"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] str [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Clipboard.GetText()
MsgBox(str)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
You may also add your own contextmenu to the WebBrowser control and set property IsWebBrowserContextMenuEnabled to False to disable the inbuilt ones.
 
i tried
VB.NET:
        Browser.Focus()
        SendKeys.SendWait("^c")
        Dim str As String = Clipboard.GetText()
and in writes that in the textbox i am assigning the value to, why is it doing this?
 
"writes that"? Post the project as a zip, so we can help debug, or as much code necessary to reproduce the problem, because it works just fine here and I can't see how it cannot.
 
Problem was you disabled keyboard shortcuts with WebBrowserShortcutsEnabled property, it have to be enabled to allow copying the selected text. If your project requires this property to be disabled, you may of course enable it for just this operation and disable it again afterwards.
 
Last edited:
About adding ContextMenu, you select this property for the control you want to add context menu to, select in combobox of available contextmenus in project.
 

Attachments

  • ctm.JPG
    ctm.JPG
    11.8 KB · Views: 85
ok i have it working but the context menu will only show before any pages are navigated to, it wont show when you are browsing
 
JohnH said:
You may also add your own contextmenu to the WebBrowser control and set property IsWebBrowserContextMenuEnabled to False to disable the inbuilt ones.
You should really be paying better attention, this is actually the third time I tell you how to do this the past three days.
 
I don't understand how that could not have worked. If you assigned you own context menu and disable the inbuilt ones in webbrowser, then your context menu is displayed. I also tried the copy selection code with a context menu item and it works flawlessly.
 
Back
Top