GreenBear
GreenBear

Reputation: 373

How to make caret visible in GeckoFX control?

I am making a WYSIWYG HTML-editor by embedding GeckoFX in a Windows Forms application in VB.NET.
This is the code:

Imports Gecko
...
Gecko.Xpcom.Initialize("C:\Program Files (x86)\XULrunner-33.0")
...
Dim gBrowser As New GeckoWebBrowser
TabControl1.SelectedTab.Controls.Add(gBrowser)
gBrowser.Dock = DockStyle.Fill
gBrowser.Navigate("about:blank")

This is how I make Web page editable:

gBrowser.Navigate("javascript:void(document.body.contentEditable='true')")

But after I make the page editable, the caret does not show up until I click the page.
How can I make caret visible at an insertion point right after the Navigate method?
This code has no visible effect:

gBrowser.SetInputFocus()
Dim fm As nsIFocusManager
fm = Xpcom.GetService(Of nsIFocusManager)("@mozilla.org/focus-manager;1")
fm = Xpcom.QueryInterface(Of nsIFocusManager)(fm)
fm.MoveCaretToFocus(gBrowser.Window.DomWindow)

Thank you.

Upvotes: 0

Views: 542

Answers (1)

Tom
Tom

Reputation: 6739

With an embedded geckofx control in a winforms application it's important to remember that there are two focus in play.

In order to set the winform focus on the geckofx control:

gBrowser.Select();

In order to set the html focus inside the geckofx control call focus on a html element. for example (where Body is a content editable element):

gBrowser.Document.Body.Focus();

Upvotes: 1

Related Questions