打印问题——————右对齐!

Jarod 2003-12-24 10:14:41
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);

private void doc_PrintPage(object sender, PrintPageEventArgs ev)
{
Font f = new Font("Arial", 12);
ev.Graphics.Drawstring("Hello, World.",f, Brushes.Black, 100, 100);
ev.HasMorePages = false;
}


打印时 是从100,100为左起点输出。

我想向票据上打出一列右对齐的数字(如货币)

请问如何指定右端点?
...全文
167 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
polarlm 2003-12-25
  • 打赏
  • 举报
回复
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Far;
polarlm 2003-12-25
  • 打赏
  • 举报
回复
查msdn
drawString函数
使用指定 StringFormat 对象的格式化属性,用指定的 Brush 和 Font 对象在指定的位置绘制指定的文本字符串。

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, PointF, StringFormat)
[C#] public void DrawString(string, Font, Brush, PointF, StringFormat);
[C++] public: void DrawString(String*, Font*, Brush*, PointF, StringFormat*);
[JScript] public function DrawString(String, Font, Brush, PointF, StringFormat);
使用指定 StringFormat 对象的格式化属性,用指定的 Brush 和 Font 对象在指定的矩形绘制指定的文本字符串。

[Visual Basic] Overloads Public Sub DrawString(String, Font, Brush, RectangleF, StringFormat)
[C#] public void DrawString(string, Font, Brush, RectangleF, StringFormat);
[C++] public: void DrawString(String*, Font*, Brush*, RectangleF, StringFormat*);
[JScript] public function DrawString(String, Font, Brush, RectangleF, StringFormat);
Jarod 2003-12-25
  • 打赏
  • 举报
回复
StringFormat sf = new StringFormat(StringFormatFlags.DirectionRightToLeft);
ev.Graphics.DrawString("Hello, World",f, Brushes.Black, 100, 100,sf);
是这样么?
甴曱 2003-12-25
  • 打赏
  • 举报
回复
可以使用:StringAlignment.Center;或者:StringAlignment.Far;或者:StringAlignment.Near;
前提条件:加上System.Draw;的引用。设置你的字符串的Alignment为上述三种的任意一种可以完成你想要的左、中、右的设置
Jarod 2003-12-25
  • 打赏
  • 举报
回复
我可能没说明白!
我想在票据上打印效果如下:
123.00
12,321.00

1,321.00

132.00

但用ev.Graphics.Drawstring("?",f, Brushes.Black, 100, 100);
只能是

123.00
12,321.00

1,321.00

132.00
咋办?
请给出部分代码!
谢谢!
xiaodele 2003-12-25
  • 打赏
  • 举报
回复
呵呵,楼上说的没错StringFormat有两个属性可以搞定的
ssdjmcj8048 2003-12-24
  • 打赏
  • 举报
回复
StringFormat对象,可以格式字符串的输出,上下左右都能搞定
NetXmlJava 2003-12-24
  • 打赏
  • 举报
回复
请参阅StyleFormat对象的说明。

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧