//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 PansuriyaRank #454 · 5.5K reputationPosted Jan 9, 2015, 12:25 AM EST
Than Accept as Correct Answer..!!
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 8, 2015, 11:48 PM EST
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 SrivastavaRank #7,688 · 236 reputationPosted Jan 8, 2015, 10:47 PM EST
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 8, 2015, 10:55 PM EST
Are you selecting text by mouse dragging or any other method for selecting text.?
Aisha SrivastavaRank #7,688 · 236 reputationPosted Jan 8, 2015, 11:04 PM EST
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 8, 2015, 11:14 PM EST
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 SrivastavaRank #7,688 · 236 reputationPosted Jan 8, 2015, 11:24 PM EST
Aisha SrivastavaRank #7,688 · 236 reputationPosted Jan 9, 2015, 12:10 AM EST
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 8, 2015, 2:49 AM EST
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();
}
}
}
}
Aisha SrivastavaRank #7,688 · 236 reputationPosted Jan 8, 2015, 11:59 PM EST