It's not clear from your example what picRooms
is, so I can't tell you how to access its Graphics from elsewhere.
Though as a general API improvement, it would be better to move the functional code out of the event handler into a method where it can be re-used;
private void DrawComplete(Graphics g)
{
if (Percent == 100)
{
g.DrawString("Completed!", font, Brushes.Black, new Point(3, 2));
}
}
And now you can call that method from anywhere;
private void picRooms_Paint(object sender, PaintEventArgs e)
{
DrawComplete(e.Graphics)
}
public void Complete()
{
DrawComplete(this.CreateGraphics());
}
Also worth nothing that in your example, since Complete
does nothing else, you might as well follow this example, but put the functional code in Complete
, not add another method the way I have.