private void ImagePanel_Paint(object sender, PaintEventArgs e) { if (null != ImageBitmap) { ImagePanel.CreateGraphics().DrawImageUnscaled(ImageBitmap, 0, 0); } else { ImagePanel.CreateGraphics().Clear(Color.White); } }
private void DrawTheImage() { Rectangle pictureOnePosAndSize = new Rectangle(20, 30, 250, 200); using (Graphics panelGraphics = ImagePanel.CreateGraphics()) { panelGraphics.Clear(Color.White); panelGraphics.DrawImage(pictureOne, pictureOnePosAndSize); } } // end DrawTheImage()
} // end DrawTheImage() private void ImagePanel_Paint(object sender, PaintEventArgs e) { // the Paint() method is called automatically, and it may be called // before a picture is loaded. So test for a null image and if null // then return from this method before the picture is used if (pictureOne == null) { // just a debug meesage to show if the picture is null when Paint() is called Console.WriteLine(" paint called pictureOne is null "); return; } Rectangle pictureOnePosAndSize = new Rectangle(20, 30, 250, 200); using (Graphics panelGraphics = ImagePanel.CreateGraphics()) { panelGraphics.DrawImage(pictureOne, pictureOnePosAndSize); } }