开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜