create mouse down event handller in run time
I write a win app,and in run time i make many controls and locate on my forms,now i want to handell the mouse down event for any control that i create,now how can i do it??it's important for me that when the mouse down event occerred ,i understand from which c开发者_StackOverflow中文版ontrol is occurred. my controls that i create are picture box. my question is clear?? thanks.
You can write control.MouseDown += SomeMethod;
and check the sender
parameter in void SomeMethod(object sender, MouseEventArgs e) { ... }
.
I would create a selection handler class and then require each of your controls to implement it. SLaks idea sounds good for something not too complex, but as you add more controls to your page a selection handler will be more efficient from both a code maintenance and code execution standpoint.
精彩评论