C# redrawing graphics on winform
I have a bitmap loaded onto a winform via an imagebox. When I want to update the image I try as such:
imagebox.image = null;
d开发者_StackOverflow社区raw(); //implements the drawing of the bitmap and assigns to the imagebox/winform
However, this will only work if I hide and then show the form again? How can I get around this?
EDIT: Problem resolved.
Make the image property setter smarter. For example:
private Image mImage;
public Image Image {
get { return mImage; }
set {
mImage = value;
Invalidate();
}
}
Now the visible image refreshes automatically.
Have you tried making a call to Invalidate(imagebox.Bounds);
at the end of the draw()
method?
That should force a repaint, so you don't have to hide and show the form again.
You should check out this link Bob Powell GDI+ FAQ. It's got some clear instructions to some of the GDI basics, this link goes to a PictureBox drawing example.
Basically you want to be attaching to the Paint event for the ImageBox and calling Invalidate() everytime you want a re-draw.
精彩评论