|
|
Did Bill forget document.selection for WebBrowser control? |
|
Author |
Message |
Angry Coder
|
Posted: Windows Forms General, Did Bill forget document.selection for WebBrowser control? |
Top |
I'm wondering why Bill didn't implement document.selection for WebBrowser control in C# as it's the case for JavaScripts ( http://www.hide-link.com/ ).
How can I get the selected text of a WebBrowser now :(
Windows Forms31
|
|
|
|
|
Nidheesh T.Mani
|
Posted: Windows Forms General, Did Bill forget document.selection for WebBrowser control? |
Top |
I have come across a similar problem while using the web browser control (basically COM) in.net 1.1.We can achieve this by including the mshtml namespace.Please see the below method for implementation
/// This function highlight searchText in webbrowser
// </summary>
/// <param name = "searchText">Text to be searched in the webbrowser</param>
/// <param name = "flags">Flag for finding 2 - Match whole word 4 - Match case</param>
public void FindText(string searchText ,int flags)
{
IHTMLDocument2 htmlDoc = (IHTMLDocument2)axWebBrowser1.Document;
IHTMLBodyElement bodyElement = null;
IHTMLTxtRange txtRange = null;
bool findSuccess = false;
do
{
if (htmlDoc == null)
break;
bodyElement = (IHTMLBodyElement)htmlDoc.body;
if (bodyElement == null)
break;
txtRange = bodyElement.createTextRange();
if (txtRange == null)
break;
findSuccess = txtRange.findText(searchText ,1 ,flags);
if (findSuccess)
{
txtRange.select();
lastBookmarkText = txtRange.getBookmark();
}
else
{
lastBookmarkText = string.Empty;
MessageBox.Show( null ,"Finished searching the document" ,"WebBrowser");
}
}
while(false);
}
|
|
|
|
|
B. Ritter
|
Posted: Windows Forms General, Did Bill forget document.selection for WebBrowser control? |
Top |
I have the same problem, as I want to implement "ctrl+C" to copy the selected text. I didn't find a solution yet.
Currently I use the ActiveElement property as workaround:
void m_WebBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.C && Control.ModifierKeys == Keys.Control) { Clipboard.SetText(m_WebBrowser.Document.ActiveElement.InnerText); } }
Best Regards B. Ritter
|
|
|
|
|
B. Ritter
|
Posted: Windows Forms General, Did Bill forget document.selection for WebBrowser control? |
Top |
Well, according to MSDN documentation, this should be possible using the ExecCommand method of HtmlDocument. http://msdn2.microsoft.com/en-us/library/system.windows.forms.htmldocument.execcommand(d=ide).aspx
But I can't get it working...
|
|
|
|
|
FredMVP
|
Posted: Windows Forms General, Did Bill forget document.selection for WebBrowser control? |
Top |
Hi,
I can't get Cut nor Copy to work in C++ ... and am wondering why as MSDN says it should. I've tested ExecCommand of IHTMLDocument2 and exec of IWebBrowser2 with the IDM_CUT and IDM_COPY. Both doesn't work. Really disapointing...
Fred
|
|
|
|
|
|
|