//Highlight selected Text
// Problem-I have current selection method but could not highlight the current selection..
Please help me out...really stuck....
If need any correction in given code please make it...
public void highlightselectedtext()
{
IHTMLDocument2 htmldocument = editorWebBrowser.Document.DomDocument as IHTMLDocument2;
IHTMLSelectionObject currentSelection = htmldocument.selection;
if (currentSelection != null)
{
IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;
if (range != null)
{
// ?????????//
}
}
Thanks in advance...Plz Help ..

Piyush PansuriyaPosted Jan 9, 2015, 5:25 AM
Than Accept as Correct Answer..!!
Aisha SrivastavaPosted Jan 9, 2015, 5:10 AM
Aisha SrivastavaPosted Jan 9, 2015, 4:59 AM
Piyush PansuriyaPosted Jan 9, 2015, 4:48 AM
Try This :
if(range != null)
{
string newhtml = ""; newhtml+=range.htmlText;
newhtml+="";
range.pasteHTML(newhtml);
}
pasteHTML text into the given text range, replacing any previous text and HTML elements in the range.
Aisha SrivastavaPosted Jan 9, 2015, 4:24 AM
Piyush PansuriyaPosted Jan 9, 2015, 4:14 AM
If you are selecting text by mouse or keyboard, browser automatically highlight that text area.
if you are using apart from text control for text than it may be happen.
Aisha SrivastavaPosted Jan 9, 2015, 4:04 AM
Piyush PansuriyaPosted Jan 9, 2015, 3:55 AM
Are you selecting text by mouse dragging or any other method for selecting text.?
Aisha SrivastavaPosted Jan 9, 2015, 3:47 AM
Piyush PansuriyaPosted Jan 8, 2015, 7:49 AM
Try This :
if (webBrowser1.Document != null)
{
IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
if (document != null)
{
IHTMLSelectionObject currentSelection = document.selection;
IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;
if (range != null)
{
const String search = "YOUR_TEXT";
if (range.findText(search, search.Length, 2))
{
range.select();
}
}
}
}