e.Graphics.DrawImage don't redraws


Bram Hoefnagel

I'm develloping a c# wm5.0 app. and run into some graphics problem,
which I can't figure out. Hopefully somebody can help me.

I draw an image on a tabpage, this image contains several ellipses on
different locations.
However there's also a combox in the tabpage, which takes care of the
selection of ellipses on the tabpage.

The problem is that the first drawing of ellipses if done well, however
after another selection there must be ellipses drawn on different
locations. This doesn't work. The old ellipses are still in place and
no new ones are drawn.

private Image _image;
private Graphics _graphics;

In the constructor I load the background image where the ellipses must
be placed on:
_image = new System.Drawing.Bitmap(PDAback.gif");

after the (combobox) selection:
_graphics = Graphics.FromImage(_image);
foreach ellipse:
_graphics.FillEllipse(new SolidBrush(Color.Red), xPosPix, yPosPix, 10,

and finally the overrided paint:
private void tabPageOverzicht_Paint(object sender, PaintEventArgs e)
// Draw image to screen.
e.Graphics.DrawImage(_image, 0, 0);
// Dispose of graphics object.
if (_graphics != null)

So the problem is that the _graphics.FillEllipse() method the second
time, fills new (different) ellipses, but the old ones are still shown,
and the new ones not.




Simon Hart

A selection of the combobox item I believe does not cause a WM_PAINT message
to be
generated, so you will explicitly need to call the Refresh() method after
the combo selection.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads