精易论坛
标题:
c# 利用控件pictureBox绘制文本
[打印本页]
作者:
chenn
时间:
2024-2-2 17:32
标题:
c# 利用控件pictureBox绘制文本
public void 绘制(string text)
{
// 获取Graphics对象
Graphics g = pictureBox1.CreateGraphics();
// 设置文本格式和样式
Font font = new Font("Arial", 12, FontStyle.Bold);
Brush brush = new SolidBrush(Color.Green);
PointF point = new PointF(70, 20); // 定义文本起始位置
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center ; // 居中对齐文本
stringFormat.LineAlignment = StringAlignment.Center; // 垂直居中行文本
// 在PictureBox上绘制文本
g.DrawString(text, font, brush, point, stringFormat);
}
欢迎光临 精易论坛 (https://125.confly.eu.org/)
Powered by Discuz! X3.4