Hi,
The browser is not like a regular TextBox. For one thing, it renders HTML, so it shouldn't be surprising that it works differently.
In order to modify or retrieve information about the cursor position you have to use a TextRange object, which provides information
about the current selection in the document.
Add a reference in your project to the Microsoft.mshtml assembly (It's a PIA that I believe ships with Office 2003. I think there
is an older COM library that you can reference instead but I can't remember its name right now).
Use the following code to get a TextRange object that represents the current selection:
IHTMLDocument2 document = (IHTMLDocument2) webBrowser1.Document.DomDocument;
if (document.selection.type == "text")
{
IHTMLTxtRange range = (IHTMLTxtRange) document.selection.createRange();
IHTMLTextRangeMetrics metrics = (IHTMLTextRangeMetrics) range;
// Here are some ways to read and manipulate the range position:
// Get the location of the bounding rectangle of the text range relative to its parent element
Point clientLocation = new Point(metrics.boundingLeft, metrics.boundingTop);
// Collapse the TextRange into a cursor ( | ) and move it to the specified point, relative to the window:
range.moveToPoint(10, 10);
}
TextRange object on MSDN:
http://msdn.microsoft.com/library/d...hor/dhtml/reference/objects/obj_textrange.asp