Click here to Skip to main content
15,891,778 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I know how to add panels on a winform at run-time, but if the number of the panels added is determined at run-time, how can I access the Paint method for each panel during run-time?
Posted

1 solution

You can also programmatically add event hooks. You can write your event handler, so in this case the shell is
C#
private void panel_Paint(object sender, PaintEventArgs e)
{

}


Then, whenever you add a new panel to the form, you add an event handler to that panel like so:
C#
Panel newPanel = new Panel();

//set panel position and other properties

//Add the event handler
newPanel.Paint += new PaintEventHandler(this.panel_Paint);

//Add it to the form
this.Controls.Add(newPanel);


Then, whenever your new panel is painted, it will go to your handler.
There's an example here[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900