我想在网络浏览器中选中复选框时引发一个事件。这是我想出的:
public class HTMLCheckBoxArgs : EventArgs
{
public Guid ElementGuid;
}
public delegate void CheckBoxChangeEventHandler(object sender, HTMLCheckBoxArgs e);
public event CheckBoxChangeEventHandler CheckPressed;
void OnCheckPressed(HTMLCheckBoxArgs args)
{
if (CheckPressed != null)
CheckPressed(this, args);
}
protected void CheckBoxEvents()
{
HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement el in elements)
{
HTMLCheckBoxArgs checkbargs = new HTMLCheckBoxArgs();
if (el.GetAttribute("type") == "checkbox")
{
checkbargs.ElementGuid = Guid.Parse(el.Id);
el.AttachEventHandler("onclick", (sender, args) => OnCheckBoxClicked(el, checkbargs));
}
}
}
public void OnCheckBoxClicked(object sender, EventArgs args)
{
OnCheckPressed((HTMLCheckBoxArgs)args);
}
我遇到的问题是这样我在单击复选框时引发了事件。我希望在选中复选框时引发事件。