Can't raise click event of a UserControl in C# -
i have dynamically added usercontrol
:
var listitem = new listitem(/* arguments */); listitem.click += setlistitemcolor; panel.controls.add(listitem); // "panel" flowlayoutpanel
setlistitemcolor:
private void setlistitemcolor(object sender, eventargs e) { var listitem = (listitem)sender; if (listitem.backcolor == color.lightgray) { listitem.backcolor = color.white; } else { listitem.backcolor = color.lightgray; } }
no change color happens when click on usercontrol
. however, test purpose, tried change event enabledchanged
and change enabled
property, color change:
var listitem = new listitem(/* arguments */); listitem.enabled = false; listitem.enabledchanged += setlistitemcolor; listitem.enabled = true; panel.controls.add(listitem);
what's problem?
edit: since docking doesn't work in flowlayoutpanel, suggest setting size of control size of panel. set listitem margins empty below maximum fill. debugging set backcolor different make sure can see it:
var listitem = new listitem(/* arguments */); listitem.backcolor = color.yellow; // debugging listitem.margin = padding.empty; listitem.size = panel.size; listitem.click += setlistitemcolor;
note if control resized need resize listitem again.
Comments
Post a Comment