0

我正在使用 c# 做一个 winforms 计费系统。我在设置打印文档中的字符串宽度时遇到问题。

如果项目描述的长度超过特定长度,我想将项目描述拆分为多行。数量、费率、金额的宽度是固定的,但项目描述的宽度可以非常根据页面宽度。

 **Item Description       Qty   Rate   Amount**

  1.Item Description-     1.0   12.00   12.00
    One 
  2.Item Description-     3.0   20.00   60.00
    Two

如何获得适合特定矩形区域的字符串编号,以便我可以拆分项目描述。

提前致谢。

4

1 回答 1

0

这样的事情会奏效吗?

const int AllowedCharactersPerLine = 16;
string example = "this is a very long string that we want to divide to fit to several lines";
string StringWithRows = "";
int n = 0;
for(int i = 0; i < example.Length; i++)
{
   StringWithRows += example.Substring(i, 1);
   n++;
   if (n == AllowedCharactersPerLine)
   {
       n = 0;
       StringWithRows += Environment.NewLine;
   }
}    
于 2013-07-09T15:39:01.847 回答