【发布时间】:2018-05-28 20:02:01
【问题描述】:
ptStart.X += 80;
g.DrawString(Math.Round(decimal.Parse(dr["Amount"].ToString()), 0).ToString(), font, brush, ptStart);
通过上面的代码得到低于输出。
但我需要右对齐。我也用过string.Format("{0,8}")。但它也不起作用
【问题讨论】:
ptStart.X += 80;
g.DrawString(Math.Round(decimal.Parse(dr["Amount"].ToString()), 0).ToString(), font, brush, ptStart);
通过上面的代码得到低于输出。
但我需要右对齐。我也用过string.Format("{0,8}")。但它也不起作用
【问题讨论】:
您应该使用允许您指定 StringFormat 的 Graphics.DrawString 版本。见:https://msdn.microsoft.com/en-us/library/21kdfbzs(v=vs.110).aspx
StringFormat的对齐方式是你需要指定的:
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Far;
您指定的 Rectangle 参数允许您指定要在其中绘制文本的区域。
【讨论】: