Hi guys I am not a c# guru and i think this is a good question to ask here. I have a pannel in which i am writing coordinates but since the cordinates change in every loop i when they change the panel gets the new coordinates on top of the old once. I need the panel to get refreshed before putting on top the new string. This is my code:

Graphics gc = coordinates.CreateGraphics();
            Font myFont;
            Brush myBrush;

            myFont = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
            myBrush = new SolidBrush(System.Drawing.Color.Red);
            gc.DrawString("left_l_chest X = " + BodyParts[13].X.ToString(), myFont, myBrush, 10, 10);//BodyParts[13].X, BodyParts[13].Y);
gc.Dispose();

I can't insert a picture but the texts gets the new text on top without erasing the old one. any help will be apreciated. thanks

Recommended Answers

All 2 Replies

Do not write string directly to the drawing, write them to the bitmap.

....
            Bitmap btm = new Bitmap(30, 30);

            Graphics t = Graphics.FromImage(btm);
            t.Clear(Color.Black);
            t.DrawString("Text here", new Font("Arial", 20f), Brushes.Red , new PointF(1, 1));
          
            g.DrawImage(btm, new Point(15, 15));
....

Thanks mate very useful idea!

Do not write string directly to the drawing, write them to the bitmap.

....
            Bitmap btm = new Bitmap(30, 30);

            Graphics t = Graphics.FromImage(btm);
            t.Clear(Color.Black);
            t.DrawString("Text here", new Font("Arial", 20f), Brushes.Red , new PointF(1, 1));
          
            g.DrawImage(btm, new Point(15, 15));
....
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.