急切问题(打印字符串)!谢谢 我以前用VB做打印时需要用到API。不太简单,用C#没做过。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用vb也做过,很简单,用c#的测量字符串长度怎么都是以象素为单位了,真是郁闷!请高人指教 可以返回以毫米为单位的,你弄错了e.Graphics.PageUnit = GraphicsUnit.Millimeter;SizeF stringSize = new SizeF();string measureString = "Measure String 分行三等功发大公司电饭锅发的国风的三个对方所国法第三个对方所国法第三个低速发弗萨第三分散地方撒发送斯蒂芬第三分散地方三大幅度缩放速度四大幅斯蒂芬第三";Font stringFont = new Font("宋体",9);// Set maximum width of string.int stringWidth = 100;//System.Convert.ToInt32(100*0.0394*600);// Set string format.StringFormat newStringFormat = new StringFormat(StringFormatFlags.LineLimit);// newStringFormat.FormatFlags = StringFormatFlags.LineLimit;Debug.WriteLine(stringWidth);// Measure string.System.Int32 ch=1,l=2;stringSize = e.Graphics.MeasureString(measureString,stringFont,new SizeF(100,400),newStringFormat,out ch,out l);// Draw rectangle representing size of string.e.Graphics.DrawRectangle(new Pen(Color.Red, 1),0,0, System.Convert.ToInt32(Math.Floor(stringSize.Width)), System.Convert.ToInt32(Math.Floor(stringSize.Height)));e.Graphics.DrawRectangle(new Pen(Color.Black),10,10,stringWidth,System.Convert.ToInt32(Math.Ceiling(stringSize.Height))+1);Debug.WriteLine(e.Graphics.DpiX);Debug.WriteLine(stringSize.Width);Debug.WriteLine(stringSize.Height);// Draw string to screen.e.Graphics.DrawString(measureString,stringFont,Brushes.Black,new Rectangle(10,10,stringWidth,System.Convert.ToInt32(Math.Floor(stringSize.Height))),newStringFormat); 【急!!】将 Winform 控件保存图像问题! 软件的中树形结构如何在数据库里建立表啊~~ 给控件添加 鼠标单击事件 messagebox窗体怎么实现? 如何使datagridview的单元格可直接编辑 c#中调用C++的动态链接库有时是好的,有时出错,有时是好的,急!!! c#中控件中的事件不能靠最上面的“常规”“声明”栏选么?? C#调用MFC的dll问题 C#监控打印机 绝对简单的问题,先来先得分。。。 请求打印解决方案? 新手问题,谢谢参与
string measureString = "Measure String 分行三等功发大公司电饭锅发的国风的三个对方所国法第三个对方所国法第三个低速发弗萨第三分散地方撒发送斯蒂芬第三分散地方三大幅度缩放速度四大幅斯蒂芬第三";Font stringFont = new Font("宋体",9);// Set maximum width of string.int stringWidth = 100;//System.Convert.ToInt32(100*0.0394*600);// Set string format.StringFormat newStringFormat = new StringFormat(StringFormatFlags.LineLimit);// newStringFormat.FormatFlags = StringFormatFlags.LineLimit;
Debug.WriteLine(stringWidth);
// Measure string.
System.Int32 ch=1,l=2;
stringSize = e.Graphics.MeasureString(measureString,stringFont,new SizeF(100,400),newStringFormat,
out ch,out l);// Draw rectangle representing size of string.e.Graphics.DrawRectangle(new Pen(Color.Red, 1),0,0, System.Convert.ToInt32(Math.Floor(stringSize.Width)), System.Convert.ToInt32(Math.Floor(stringSize.Height)));
e.Graphics.DrawRectangle(new Pen(Color.Black),10,10,stringWidth,System.Convert.ToInt32(Math.Ceiling(stringSize.Height))+1);Debug.WriteLine(e.Graphics.DpiX);
Debug.WriteLine(stringSize.Width);
Debug.WriteLine(stringSize.Height);// Draw string to screen.e.Graphics.DrawString(measureString,stringFont,Brushes.Black,new Rectangle(10,10,stringWidth,System.Convert.ToInt32(Math.Floor(stringSize.Height))),newStringFormat);