简体   繁体   中英

how to draw fixed string on pictureBox using C#?

I have to draw some text on pictureBox image (Gray scale image). I got some codes. its working but its moving with the image while panning and zooming, and it disappear while changing the window level.

            rect = pictureBox1.ClientRectangle;
            Graphics g = Graphics.FromImage(bmp);
            SolidBrush brush = new SolidBrush(Color.Green);
            Font f = new Font("Arial", 15);
            g.DrawString("Murugesan", f, brush, start);

I want the text in the permanent location and it never disappear while changing the window level. Anybody there to help me.

You should draw it on PictureBox OnPaint event and use e.Graphics.

Probably you wouldn't have artifacts you mentioned if you used:

Graphics g = pictureBox.CreateGraphics();

But paint on event is still better than that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM