c# - Click event not working on dynamically added button or Panel -


i using following code in c# add button

button textlabel = new button(); //local variable textlabel.location = new point(0, 0); textlabel.visible = true; textlabel.enabled = true; textlabel.autosize = true; textlabel.click += click; this.controls.add(textlabel); 

and click handler is

protected void click(object o, eventargs e) {    messagebox.show("hello"); } 

though button visible , responding mouse hover, nothing happening on click. wrong or missing? if write same code in independent project, works!!!!! strange. why????

form properties: (if required)
1. show in taskbar: false
2. borderless
3. 50% opaque

today realised registering click event control not make event work unless parent (in case form) on control still active.

parent control receive event notification earlier child controls. simple , obvious observation, if not paid attention make undesirable effects.

that's mistake did, made form active on form activated event, hence control in didn't received events mouse clicks.

talking of 'hover effects working', yes, if form inactive, hover works.

so removed line of code made form active , working fine now.

private void form1_activated(object sender, eventargs e) {     //if (form2!=null) form2.bringtofront(); //commented } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -