Search code examples
c#system.drawing

Graphics not showing up in C#


I have a picturebox that has an image in it and a top of this image I am drawing some ellipses. However, only some of the ellipses show up. Code looks something like this:

Graphics g = Graphics.FromHwnd(pictureBox1.Handle); 
g.FillEllipse(redBrush, rfidNode1.readerPos.X, rfidNode1.readerPos.Y, 15, 15);

EDIT: I'm sorry I copied and pasted the last line twice...so there is only one line that fills the ellipse. Also, x and y are within the range of the picture box.


Solution

  • Could you try something like this? (change the dimensions if needed)

    Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
    Graphics g = Graphics.FromImage(bmp);
    g.FillEllipse(redBrush, rfidNode1.readerPos.X, rfidNode1.readerPos.Y, 15, 15);
    pictureBox1.Image = bmp;
    

    Or maybe I missed your intentions?