Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Sql Reporting Services 2005将一个长字符串从一个文本框延续到另一个文本框_C#_Reporting Services_Textbox_Reportingservices 2005 - Fatal编程技术网

C# Sql Reporting Services 2005将一个长字符串从一个文本框延续到另一个文本框

C# Sql Reporting Services 2005将一个长字符串从一个文本框延续到另一个文本框,c#,reporting-services,textbox,reportingservices-2005,C#,Reporting Services,Textbox,Reportingservices 2005,我有一份SQL Reporting Services 2005报告,第一页包含一个文本框。文本框的字符串输入可能非常大,并且包含换行符。文本框大小是固定的,报告的第二页包含另一个文本框,用于处理第一页文本框中不适合的溢出文本。如果第二页的文本框变满了,那么我想在文本末尾加一个“…”来表示一些文本被截断了 我尝试过使用TextRenderer.MeasureText()方法,但它似乎只适用于单行。我正在尝试以下代码 string str = string.Copy(commentString);

我有一份SQL Reporting Services 2005报告,第一页包含一个文本框。文本框的字符串输入可能非常大,并且包含换行符。文本框大小是固定的,报告的第二页包含另一个文本框,用于处理第一页文本框中不适合的溢出文本。如果第二页的文本框变满了,那么我想在文本末尾加一个“…”来表示一些文本被截断了

我尝试过使用TextRenderer.MeasureText()方法,但它似乎只适用于单行。我正在尝试以下代码

string str = string.Copy(commentString);
TextFormatFlags flags = TextFormatFlags.WordBreak |
                        TextFormatFlags.WordEllipsis |
                        TextFormatFlags.ModifyString;
float textBoxWidthInches = 3.8f;
float textBoxHeightInches = 3.4f;
Size size = new Size(
    (int)(textBoxWidthInches * 72 - 2),
    (int)(textBoxHeightInches * 72 - 2));
TextRenderer.MeasureText(str, new Font("Arial", 8), size, flags);
然后,我希望str在需要断开字符串的位置包含一个“\0”,但是,它没有出现。如果我删除WordBreak标志并输入一个第一行很长的字符串,它确实会在第一行的正确位置包含“\0”,但它只适用于一行

我的问题是:

1) 在Sql Reporting Services 2005中,如何将文本从一个文本框“继续”到另一个文本框

2) 如果没有,我如何计算我需要在哪里分解我的字符串以使其适合文本框

3) 或者,我想在第二个文本框的末尾添加一个“…”来表示超出两个文本框所能容纳的长度的文本

编辑: 我试图实现的是这样的目标:

|------------------------|
|                        |
|     Header Page 1      |
|------------------------|
|        |               |
|        |               |
|TextBox1|               |
|        |               |
|--------|               |
|                        |
| Other Data             |
|                        |
|                        |
|                        |
|                        |
|                        |
|                        |
|                        |
|------------------------|


|------------------------|
|                        |
|     Header Page 2      |
|------------------------|
|        |               |
|        |               |
|TextBox2|               |
|        |               |
|--------|               |
|                        |
| Other Data             |
|                        |
|                        |
|                        |
|                        |
|                        |
|                        |
|                        |
|------------------------|

然后我希望TextBox1继续到第二页的TextBox2。使用CanGrow属性将无法获得所需的行为

设置CanGrow后,一旦高度大于一页,文本框将拆分为多页。如果文本框与另一个控件共享一个页面,它将首先移动到第二个页面。看

如果必须将文本框剪切为两页,则可以将文本框大小设置为2页,然后将CanGrow设置为false,CANSCRING设置为true。这样,文本框将始终小于2页


然后测试文本中的行数(您可能需要编写一个函数来完成此操作)与文本框中可以容纳的行数,以控制包含消息“进一步文本截断”的另一个文本框的可见性

您还可以通过使用表格、分组和分组后打断来近似这种行为。因此,第1页将是group1的第一个值,第2页将是group1的第二个值,以此类推


详细信息组将是页面的内容(如果您愿意,也可以添加更多分组)

以下是我的结论:

  public static IList<string> WordWrap(
     string text,
     Font printFont,
     Graphics graphics,
     IList<SizeF> sizeF,
     string tooLongText)
  {
     List<string> list = new List<string>();
     int charsFit;
     int linesFilled;

     foreach (SizeF size in sizeF)
     {

        graphics.MeasureString(
           text,
           printFont,
           size,
           new StringFormat(),
           out charsFit,
           out linesFilled);

        char[] whitespace = new[] { ' ', '\t', '\r', '\n' };
        int index = charsFit;

        if (text.Length > charsFit)
           index = text.LastIndexOfAny(whitespace, charsFit);

        if (index < 0) index = charsFit;

        string rv = text.Substring(0, index).Trim();
        text = text.Substring(index).Trim();
        list.Add(rv);
     }

     if (!string.IsNullOrEmpty(text))
     {
        string lastText = list[list.Count - 1];
        SizeF size = sizeF[sizeF.Count - 1];
        charsFit = 0;
        string newLastText = lastText + Environment.NewLine + tooLongText;
        while (charsFit < newLastText.Length)
        {
           graphics.MeasureString(
              newLastText,
              printFont,
              size,
              new StringFormat(),
              out charsFit,
              out linesFilled);
           lastText = lastText.Substring(0, lastText.Length - 1);
           newLastText = lastText + Environment.NewLine + tooLongText;
        }

        list.RemoveAt(list.Count - 1);
        list.Add(newLastText);
     }

     return list;
  }
公共静态IList WordWrap(
字符串文本,
字体打印字体,
图形,
IList sizeF,
字符串(文本)
{
列表=新列表();
int charsFit;
内线填充;
foreach(SizeF中的SizeF大小)
{
图形测量(
文本,
打印字体,
大小,
新建StringFormat(),
查斯菲特,
外线填充);
char[]whitespace=new[]{','\t','\r','\n'};
int index=charsFit;
如果(text.Length>charsFit)
index=text.LastIndexOfAny(空格、字符位);
如果(索引<0)索引=字符位;
字符串rv=text.Substring(0,index.Trim();
text=text.Substring(index.Trim();
列表。添加(rv);
}
如果(!string.IsNullOrEmpty(text))
{
字符串lastText=list[list.Count-1];
SizeF size=SizeF[SizeF.Count-1];
charsFit=0;
字符串newLastText=lastText+Environment.NewLine+tooLongText;
while(charsFit

然后为我的两个文本框生成两个公共字符串属性。如果此函数返回计数大于0的列表,则第一个文本框值=列表[0]。如果列表计数>1,则第二个文本框值=列表[1]。我确信这不是最好的代码,但它满足了我的需要。

谢谢你的回答,但我已经尝试了所有我能想到的方法,使用CanGrow和CanShrink,但无法获得所需的行为。我编辑了我的文章,给出了所需输出的示例。