QuickReport报表中QRLabel显示的数据的换行问题
在用QuickReport做报表时,用QRLabel显示数据,但是QRLabel并不直接支持换行,需要用属性设置
WordWrap为true, 和AotoStretch 属性为true.为了能随着内容的变化动态的换行.我写的程序和修改后的程序,代码如下:
int iLength; //要显示的文字的总长度
int iRows; //行数
int iY; //余数
AnsiString temp = ""; //存放临时字符串
String Str;
//使报表值自动换行
iLength = strlen(Str.c_str());
iRows = iLength / 100;
iY = iLength % 100;
if (iRows == 0)
{
lbl->Caption = Str;
}
if ((iRows == 1) && (iY > 0))
{
lbl->Caption = Str.SubString(1, 100) + " ";
}
if ((iRows > 1) && (iY >= 0))
{
for (int i = 0; i < iRows; i++)
{
temp += Str.SubString(i * n + 1, (i + 1) * n) + " ";
lbl->Caption = temp;
}
/*******************************************************************************
FunctionName: AutoNewLine
Description: 报表组件QRLabel的显示的信息的自动换行函数
Date: 2004-11-13
参数说明:lbl TQRLabel 类型
Str 要显示的字符串
n 组件每行显示的字符的长度
********************************************************************************/
void AutoNewLine(TQRLabel *lbl, AnsiString Str, int n)
{
int iLength; //要显示的文字的总长度
int iRows; //行数
int iY; //余数
AnsiString temp = ""; //存放临时字符串
iLength = strlen(Str.c_str());
iRows = iLength / n;
iY = iLength % n;
if ((iRows == 0) || ((iRows == 1) && (iY == 0)))
{
lbl->Caption = Str;
}
if ((iRows == 1) && (iY >= 0)) //表示有余数,还不够两行
{
lbl->Caption = Str.SubString(1, n) + " ";
}
if ((iRows > 1) && (iY >= 0))
{
for (int i = 0; i < iRows; i++)
{
temp += Str.SubString(i * n + 1, (i + 1) * n) + " ";
lbl->Caption = temp;
}
}
/*
if (((iRows == 0) && (iY > 0)) || ((iRows == 1) && (iY == 0)))
{
lbl->Caption = Str;
}
else
{
for (int i = 0; i < iRows; i++)
{
temp += Str.SubString(i * n + 1, (i + 1) * n) + " ";
lbl->Caption = temp;
}
}
*/
}
请大家帮忙看一看,如果分数不够,可以再加.