简体   繁体   English

如何使用C#在pictureBox上绘制固定字符串?

[英]how to draw fixed string on pictureBox using C#?

I have to draw some text on pictureBox image (Gray scale image). 我必须在pictureBox图像(灰度图像)上绘制一些文本。 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. 您应该在PictureBox OnPaint事件上绘制它,并使用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. 但是在事件上绘画仍然比这更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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