如何在drawString绘出的文字上加入背景颜色
展开全部
你在绘制字符串之前可以使用Graphics的MeasureString方法测量它的尺寸再绘制一个相应大小的矩形就行了,如下
Graphics g = this.CreateGraphics();
Font font = new Font("宋体", 9f);
PointF pointF = new PointF(10, 10);
SizeF sizeF = g.MeasureString("Hello World!", font);
g.FillRectangle(Brushes.White, new RectangleF(pointF, sizeF));
g.DrawString("Hello World!", font, Brushes.Black, pointF);
g.Dispose();
font.Dispose();
Graphics g = this.CreateGraphics();
Font font = new Font("宋体", 9f);
PointF pointF = new PointF(10, 10);
SizeF sizeF = g.MeasureString("Hello World!", font);
g.FillRectangle(Brushes.White, new RectangleF(pointF, sizeF));
g.DrawString("Hello World!", font, Brushes.Black, pointF);
g.Dispose();
font.Dispose();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询