end;................ implementation...............//修改下列过程 Procedure TReportCell.CalcMinCellHeight; .................. //找到 下面代码段 Case FHorzAlign Of 0: Format := Format Or DT_LEFT; 1: Format := Format Or DT_CENTER; 2: Format := Format Or DT_RIGHT; Else Format := Format Or DT_LEFT; End;
//在Case语句前面加上 If fWordBreak Then Format := DT_EDITCONTROL Or DT_WORDBREAK Else Format := DT_EditControl; 寻找下面过程 Procedure TReportCell.PaintCell(hPaintDC: HDC; bPrint: Boolean); ............... ............... 寻找下面代码段: SelectObject(hPaintDC, hPrevPen); DeleteObject(hTempPen); // 绘制文字 If Length(FCellText) > 0 Then Begin Windows.SetTextColor(hPaintDC, FTextColor); //在此处添加 Format := DT_EditControl; Case FHorzAlign Of TEXT_ALIGN_LEFT: Format := Format Or DT_LEFT; TEXT_ALIGN_CENTER: Format := Format Or DT_CENTER; TEXT_ALIGN_RIGHT: Format := Format Or DT_RIGHT; Else Format := Format Or DT_LEFT; End; 在上面注明的地方添加 If fWordBreak Then Format := DT_EDITCONTROL Or DT_WORDBREAK Else 过程 Constructor TReportCell.Create; 里最后添加上 fAutoWidth := False; //自动展宽特性 fWordBreak := True; //自动折行特性 添加3个过程 //调整边界 Procedure TReportCell.AdjustBounds; Var DC: HDC; SaveFont: HFont; TextSize: TSize; HF: THandle; Begin If (FAutoWidth) And (CellText <> '') Then Begin DC := GetDC(0); HF := CreateFontInDirect(FLogFont); SaveFont := SelectObject(DC, HF); GetTextExtentPoint32(DC, PChar(CellText), Length(CellText), TextSize); SelectObject(DC, SaveFont); ReleaseDC(0, DC); fCellWidth := TextSize.Cx + 12; End; End;//自动单元格宽度 Procedure TReportCell.SetAutoWidth(Const Value: Boolean); Begin fAutoWidth := Value; If fAutoWidth then fWordBreak := false; AdjustBounds; End; //自动折行 Procedure TReportCell.SetWordBreak(Const Value: Boolean); Begin fWordBreak := Value; If fWordBreak Then fAutoWidth := False; End;
TReportCell = class(TWinControl)
private
......
fWordBreak: Boolean;
fAutoWidth: Boolean;
Procedure SetAutoWidth(Const Value: Boolean);
Procedure SetWordBreak(Const Value: Boolean);
Procedure AdjustBounds;
published
Property WordBreak: Boolean Read fWordBreak Write SetWordBreak;
Property AutoWidth: Boolean Read fAutoWidth Write SetAutoWidth;
end;................
implementation...............//修改下列过程
Procedure TReportCell.CalcMinCellHeight;
..................
//找到 下面代码段
Case FHorzAlign Of
0:
Format := Format Or DT_LEFT;
1:
Format := Format Or DT_CENTER;
2:
Format := Format Or DT_RIGHT;
Else
Format := Format Or DT_LEFT;
End;
//在Case语句前面加上
If fWordBreak Then
Format := DT_EDITCONTROL Or DT_WORDBREAK
Else
Format := DT_EditControl;
寻找下面过程
Procedure TReportCell.PaintCell(hPaintDC: HDC; bPrint: Boolean);
...............
...............
寻找下面代码段:
SelectObject(hPaintDC, hPrevPen);
DeleteObject(hTempPen); // 绘制文字
If Length(FCellText) > 0 Then
Begin
Windows.SetTextColor(hPaintDC, FTextColor); //在此处添加 Format := DT_EditControl;
Case FHorzAlign Of
TEXT_ALIGN_LEFT:
Format := Format Or DT_LEFT;
TEXT_ALIGN_CENTER:
Format := Format Or DT_CENTER;
TEXT_ALIGN_RIGHT:
Format := Format Or DT_RIGHT;
Else
Format := Format Or DT_LEFT;
End;
在上面注明的地方添加
If fWordBreak Then
Format := DT_EDITCONTROL Or DT_WORDBREAK
Else
过程 Constructor TReportCell.Create;
里最后添加上
fAutoWidth := False; //自动展宽特性
fWordBreak := True; //自动折行特性
添加3个过程
//调整边界
Procedure TReportCell.AdjustBounds;
Var
DC: HDC;
SaveFont: HFont;
TextSize: TSize;
HF: THandle;
Begin
If (FAutoWidth) And (CellText <> '') Then
Begin
DC := GetDC(0);
HF := CreateFontInDirect(FLogFont);
SaveFont := SelectObject(DC, HF);
GetTextExtentPoint32(DC, PChar(CellText), Length(CellText), TextSize);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
fCellWidth := TextSize.Cx + 12;
End;
End;//自动单元格宽度
Procedure TReportCell.SetAutoWidth(Const Value: Boolean);
Begin
fAutoWidth := Value;
If fAutoWidth then
fWordBreak := false;
AdjustBounds;
End;
//自动折行
Procedure TReportCell.SetWordBreak(Const Value: Boolean);
Begin
fWordBreak := Value;
If fWordBreak Then
fAutoWidth := False;
End;