请问如何设置DrawString的StringFormat属性 使用Graphics.DrawString (String, Font, Brush, Single, Single, StringFormat)将一个字符串"111111"显示为 1 1 1 1 1 1 请问该如何设置StringFormat属性? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个用不到StringFormat Graphics _Graphics = Graphics.FromHwnd(this.Handle); string _Value = "11111111111"; Font _SetFont = new Font("宋体", 20.5f); SizeF _Size =_Graphics.MeasureString(_Value,_SetFont,(int)_SetFont.Size); _Graphics.DrawString(_Value, _SetFont, Brushes.Red, new Rectangle(0, 0, (int)_Size.Width, (int)_Size.Height));这样看看. 楼主的想法用StringFormat实现不了,只能自己处理了。 只要保证StringFormat是可以折行的就行了,默认格式就是折行的。参考:protected override void OnPaint(PaintEventArgs e){ base.OnPaint(e); string str = "111111"; Size size = TextRenderer.MeasureText(str, this.Font); Rectangle rect = new Rectangle(20, 20, size.Height, (this.Font.Height)*str.Length); e.Graphics.DrawString(str, this.Font, SystemBrushes.ControlText, rect); e.Graphics.DrawRectangle(SystemPens.ControlText, rect);} 如果要显示 为11111 字符串可以这样 "1\n1\n1\n1\n1\n"如果 1倒着显示 ---------- StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.FormatFlags = StringFormatFlags.DirectionVertical; sf.LineAlignment = StringAlignment.Near; 好像是 StringFormatFlags.DirectionVertical 吧~~~ 把字符串定义为"1\n1\n1\n1\n1\n1" VS2010能否生成 方法清单? listview如何设置才能显示 替换字符串中的HTML标签 瞧一瞧看一看啦!知道的不知道的都来捧个场吧 树型结构的checkbox的问题???? 高手来看看 下面的代码在DataGridView下面应该如何修改 一个web程序如何和一个winform程序通讯呀? 关于Select count(*)的一个问题,望大神解答 PPC上如何使用MSMQ发送消息! 奇怪的问题,大家来看看 C#怎么释放文件 一个事件的小问题
Font _SetFont = new Font("宋体", 20.5f);
SizeF _Size =_Graphics.MeasureString(_Value,_SetFont,(int)_SetFont.Size);
_Graphics.DrawString(_Value, _SetFont, Brushes.Red, new Rectangle(0, 0, (int)_Size.Width, (int)_Size.Height));这样看看.
只能自己处理了。
{
base.OnPaint(e);
string str = "111111";
Size size = TextRenderer.MeasureText(str, this.Font);
Rectangle rect = new Rectangle(20, 20, size.Height, (this.Font.Height)*str.Length);
e.Graphics.DrawString(str, this.Font, SystemBrushes.ControlText, rect);
e.Graphics.DrawRectangle(SystemPens.ControlText, rect);
}
1
1
1
1
1
字符串可以这样 "1\n1\n1\n1\n1\n"
如果 1倒着显示
--
--
--
--
--
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.FormatFlags = StringFormatFlags.DirectionVertical;
sf.LineAlignment = StringAlignment.Near;