Link to home
Create AccountLog in
Avatar of elmbrook
elmbrook

asked on

Insert text into webbrowser control where cursor is currently placed

Hi
I have a windows form with a webbrowser control.

I am trying to insert some text programmatically into the webbrowser document where the cursor is currently placed.
IHTMLDocument2 doc = txtBody.Document.DomDocument as IHTMLDocument2;

if (doc != null)
                {
                    var currentSelection = doc.selection;
                    if (currentSelection != null)
                    {
                        var selectionRange = currentSelection.createRange();
                        if (selectionRange != null)
                        {
                            var selectionText = selectionRange.Text; //this equals null so cannot insert anything

                            txtBody.DocumentText.Insert(selectionText , "Hello"); // supposed to insert text
                        }
                    }
                }     

Open in new window

 

I need to find the equivalent of SelectionStart property on a text box.

Greatly appreciate any help
ASKER CERTIFIED SOLUTION
Avatar of elmbrook
elmbrook

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account