我以前用VB做打印时需要用到API。
不太简单,用C#没做过。

解决方案 »

  1.   

    我用vb也做过,很简单,用c#的测量字符串长度怎么都是以象素为单位了,真是郁闷!请高人指教
      

  2.   

    可以返回以毫米为单位的,你弄错了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);