Raising event when the checkbox of a webbrowser is checked in C# -
i want raise event when checkbox checked in web browser. here have come with:
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); }
the problem have fact way raise event when check box clicked. want event raised when check box checked.
try this:
public partial class form1 : form { public form1() { initializecomponent(); webbrowser1.documentcompleted += new webbrowserdocumentcompletedeventhandler(webbrowser1_documentcompleted); } private void form1_load(object sender, eventargs e) { webbrowser1.documenttext = "<html><body><input type=\"checkbox\" id=\"chk\" value=\"some\">some thing</body></html>"; } void webbrowser1_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { foreach (htmlelement el in webbrowser1.document.all) { if (el.getattribute("type") == "checkbox") { el.attacheventhandler("onclick", (send, args) => onelementclicked(el, eventargs.empty)); } } } private object onelementclicked(htmlelement el, eventargs eventargs) { if (el.getattribute("checked") == "true") { messagebox.show("checked"); } return false; } }
Comments
Post a Comment