Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a function, this function contains code to draw on a control which has not "CreateGraphics" method (this control is on Form). How to create this function? Thanks.
Posted

1 solution

Can pass Graphics instance or that Control instance as parameter to the function:
C#
private void DrawFunction(Control control)
{
   // Create a Graphics object for the Control.
   Graphics g = control.CreateGraphics();
   // Draw shapes etc...
}

private void DrawFunction(Graphics graphics)
{
   //Draw shapes etc...
}
 
Share this answer
 
Comments
Andrewpeter 30-Aug-12 4:19am    
Thank you, it is great code. I have found out another solution:

private void DrawFunction(System.Drawing.Printing.PrintPageEventArgs e)
{
// Draw shapes etc...
}

"e" parameter is got from Paint event of the control. Thank you very much.
Andrewpeter 30-Aug-12 4:20am    
My vote is 5. Thanks.

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