c# sending a click event from a run-time drawn object
I have a simple programme that allows input of details about a job and assign dates. Im using the project to learn c# and believe I have come a long way.
I am trying to achieve a user friendly date range input system. and because I'm using the experience to learn the programme I have decided to produce a class that draws a calender on forms when needed.
The class works very well for its initial requirements. It takes in an object (the form normally) and a point. The class then searched the database for any dates within a given range (starting with today() but can be manipulated by the form) and shows a month style block of boxes with the date and any information contained with the database.
But now I want to go the next step, and allow p开发者_运维问答eople to click on a specific date to select it and for a specific piece of code to be fired off. .. the only issue is! :
How do I programme a click event from the form, related to a label/drawn box that isn't there at design time...
since the labels are dynamically created at runtime I don't yet have a way to directly assign to them. I could recode the class for this, but would rather not if another way is possible.
Ideally im looking for a solution (if one exists) where when the label is clicked a method is passed the label.text. Could anyone point me in the right direction as to how to code the click event for anyone of the 50 labels that isn't created until run time?
Thanks for time to read, and even more thanks to those that reply.
Kind Regards Paul
this.Controls["myDynamicallyCreatedControl"].Click
+= new EventHandler(MyEventHandlerMethod_Click);
private void MyEventHandlerMethod_Click(object sender, EventArgs e)
{
// Handle click event here.
}
精彩评论