如何维护 RDLC 报告列中的长文本?
How to maintain long text inside RDLC report column ?
我尝试了很多方法来在 RDLC 报告的列中维护长文本,但它似乎不可调整。当一些长文本出现在任何列中时,它会扰乱整个报告。如何控制,让文字一直往下延伸得恰到好处。
尝试设置固定的列宽并将 CanGrow
设置为 False,并确保 Row 将其设置为 True。
如果这不起作用,您必须先编辑数据源,然后再将其提供给记者。您必须根据字符串的长度将值分成多行。您可以通过在每次超出大小时插入 System.Environment.NewLine
来实现。您需要插入换行符的确切长度取决于您的最大列宽,您必须通过反复试验自己计算,直到找到最合适的长度。
编辑:包括根据文本大小添加分界线的分步过程。
Calculate the length of the string and add Environment.NewLine
where needed to force the text to break to a new line.
- Use
Graphics.MeasureString
to calculate the size of your text in pixels.
- Check if the width exceeds the maximum length of your TextBox.
- If the string fits, add it to the final string and continue to step 4.
- If the string doesn't fit, continue to step 3.
- Remove a character of the string, insert that character to the front of a new (second) sting and repeat step 1. again until the
first string fits.
- Check if the second string is empty.
- If the second string is empty, we're finished. (The final string can be added to the TextBox / new datasource).
- If the second string isn't empty, add an
Environment.NewLine
at the end of the final string and replace the first string with the
second one and make the second string empty again, repeat the whole
process.
可能有改进此过程的方法。例如,以固定的预定义间隔分解文本,然后再对其进行细化。或者,如果有实际单词被空格分隔,您可以添加和删除单词而不是字符。
- 剪长篇
textbox
。
- 将
rectangle
拖放到那里。
- 将
textbox
粘贴到 rectangle
中。
- 设置矩形的边框
就像文本框一样。
注意:您的文本框必须是
Cangrow:true
我尝试了很多方法来在 RDLC 报告的列中维护长文本,但它似乎不可调整。当一些长文本出现在任何列中时,它会扰乱整个报告。如何控制,让文字一直往下延伸得恰到好处。
尝试设置固定的列宽并将 CanGrow
设置为 False,并确保 Row 将其设置为 True。
如果这不起作用,您必须先编辑数据源,然后再将其提供给记者。您必须根据字符串的长度将值分成多行。您可以通过在每次超出大小时插入 System.Environment.NewLine
来实现。您需要插入换行符的确切长度取决于您的最大列宽,您必须通过反复试验自己计算,直到找到最合适的长度。
编辑:包括根据文本大小添加分界线的分步过程。
Calculate the length of the string and add
Environment.NewLine
where needed to force the text to break to a new line.
- Use
Graphics.MeasureString
to calculate the size of your text in pixels.- Check if the width exceeds the maximum length of your TextBox.
- If the string fits, add it to the final string and continue to step 4.
- If the string doesn't fit, continue to step 3.
- Remove a character of the string, insert that character to the front of a new (second) sting and repeat step 1. again until the first string fits.
- Check if the second string is empty.
- If the second string is empty, we're finished. (The final string can be added to the TextBox / new datasource).
- If the second string isn't empty, add an
Environment.NewLine
at the end of the final string and replace the first string with the second one and make the second string empty again, repeat the whole process.
可能有改进此过程的方法。例如,以固定的预定义间隔分解文本,然后再对其进行细化。或者,如果有实际单词被空格分隔,您可以添加和删除单词而不是字符。
- 剪长篇
textbox
。 - 将
rectangle
拖放到那里。 - 将
textbox
粘贴到rectangle
中。 - 设置矩形的边框
就像文本框一样。
注意:您的文本框必须是
Cangrow:true