المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Re-painting a PictureBox?



C# Programming
03-31-2009, 01:40 PM
I want to paint a selection image on top of the existing image of a PictureBox (just changing the BorderStyle looks ugly if you select more than one).

So far I have this:g = Graphics.FromImage(((PictureBox)sender).Image);
g.DrawImageUnscaled(new Bitmap(filepath), 0, 0); where g is a Graphics object and filepath is the absolute path of the selection image.
Is there a way to use a relative path, I tried just using the filename and "Images\Selection\Selection Image" but these wouldn't work.

Anyway, how do I make the PictureBox re-pait itself the moment you select it?
I tried adding something like thisthis.InvokePaint(((PictureBox)sender),new PaintEventArgs(this.CreateGraphics(), ((PictureBox)sender).ClientRectangle)); but it didn't make a difference, with or without the PictureBox only gets re-painted when the whole form gets re-painting, but not immediately.

Thanks.