Click here to Skip to main content
15,847,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Wondering if you can help me, I am currently working on a project on which I use a panel and a bitmap as a canvas on the bitmap to draw and place images and controls. Which all works fine, the only problem now is. I don't know how to go about refreshing the bitmap.
I've tried almost everything and the only thing that seems to work is

Application.Restart(); - which is not really what I should be using.

Please help, Thanks in Advance

Storxstar
Posted
Comments
OriginalGriff 13-Nov-12 4:09am    
How are you using the bitmap at the moment? Are you loading it from disk and painting it yourself, or displaying it via some controls Image property?
Storxstar 13-Nov-12 4:18am    
Im painting it myself basically, using mouse points to draw lines, place images(inside pictureboxes), placing labels.

Here is the code I used to initialize the Bitmap.

Bitmap drawing;
drawing = new Bitmap(drawPanel.Width, drawPanel.Height, drawPanel.CreateGraphics());

private void drawPanelControl_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImageUnscaled(drawing, new Point(0, 0));
}
BobJanova 13-Nov-12 4:28am    
And where do you draw it?

It looks like you have everything hooked up correctly and you just need to draw all over 'drawing' again.
Storxstar 13-Nov-12 4:32am    
Im drawing it on my Panel. I've tried this for Refresh. But it doesn't seem to work either...

panel.CreateGraphics().DrawImageUnscaled(drawing, new Point(0, 0));
BobJanova 13-Nov-12 5:08am    
No, where do you do stuff to 'drawing'? All you've shown so far is where you use 'drawing' by painting it onto a control. Calling that again will refresh the control, but with the same image that it had before. You need to call again the code that actually creates the drawing.

1 solution

All you need to do is call the Panel.Invalidate method - it will cause your Paint event to be signaled again, and the drawing will be refreshed.
 
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