积极答复者
绘图的坐标问题

问题
-
Font tempFont; SizeF sizeF; Int32 x = 0; Int32 y = 0; Rectangle rectangle = Rectangle.Empty; for (int i = 0; i < sourceString.Length; i++) { tempFont = Font; sizeF = graphics.MeasureString(sourceString[i].ToString(), tempFont); if (i > 0) { x = x + (Int32)sizeF.Width; } rectangle = new Rectangle(x, y, (Int32)sizeF.Width, (Int32)sizeF.Height); graphics.DrawString(sourceString[i].ToString(), tempFont, new SolidBrush(FontColor), rectangle);
与
graphics.DrawString(sourceString, Font, new SolidBrush(FontColor), 0, 0);
结果不同, 坐标是不是计算错误?
答案
-
你好
你所说的不一样是指上面的数据少了9是吗?
我尝试了
没有出现你的问题呀,你可以再试试。string sourceString="123456789"; Graphics graphics = e.Graphics; Font tempFont; SizeF sizeF; Int32 x = 0; Int32 y = 0; Rectangle rectangle = Rectangle.Empty; for (int i = 0; i < sourceString.Length; i++) { tempFont = Font; sizeF = graphics.MeasureString(sourceString[i].ToString(), tempFont); if (i > 0) { x = x + (Int32)sizeF.Width; } rectangle = new Rectangle(x, y, (Int32)sizeF.Width, (Int32)sizeF.Height); graphics.DrawString(sourceString[i].ToString(), tempFont, new SolidBrush(Color.Red), rectangle); }
Cookie Luo[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Cookie Luo 2011年1月31日 1:49
全部回复
-
你好
你所说的不一样是指上面的数据少了9是吗?
我尝试了
没有出现你的问题呀,你可以再试试。string sourceString="123456789"; Graphics graphics = e.Graphics; Font tempFont; SizeF sizeF; Int32 x = 0; Int32 y = 0; Rectangle rectangle = Rectangle.Empty; for (int i = 0; i < sourceString.Length; i++) { tempFont = Font; sizeF = graphics.MeasureString(sourceString[i].ToString(), tempFont); if (i > 0) { x = x + (Int32)sizeF.Width; } rectangle = new Rectangle(x, y, (Int32)sizeF.Width, (Int32)sizeF.Height); graphics.DrawString(sourceString[i].ToString(), tempFont, new SolidBrush(Color.Red), rectangle); }
Cookie Luo[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Cookie Luo 2011年1月31日 1:49