问题
Is there a way to handle Gecko.DOM.GeckoInputElement click event? I have a submit button in a tag and I'd like to rise an event when I click it with the mouse. The website is open in a Gecko Browser.
I'm useing xulrunner-29.0b2.en-US.win32 and GeckoFx-Windows-29.0-0.1
My code is:
Friend WithEvents inputElement As Gecko.DOM.GeckoInputElement
Private Sub inputElement_click() Handles inputElement.Click
MsgBox("a")
End Sub
but obviously "inputElement.Click" doesn't exists.
回答1:
The easiest way to do this is to add a DomClick Handler to the main control.
C#
browser.DomClick += click;
Then inside the handler look for your button and responded appropriately.
C#
click( object sender, DomEventArgs e )
{
if ( sender == null ) return;
if ( e == null ) return;
if ( e.Target == null ) return;
var element = e.Target.CastToGeckoElement();
GeckoHtmlElement clicked = element as GeckoHtmlElement;
if ( clicked == null ) return;
if ( clicked.TagName.ToLowerInvariant() == "input" && clicked.GetAttribute("type").ToLowerInvariant() == "submit" )
{
e.Handled = true;
MessageBox.Show("a");
}
来源:https://stackoverflow.com/questions/25566626/vb-net-how-to-handle-a-gecko-dom-geckoinputelement-click-event