stringgrid的字同一列字如何换行
答案:1 悬赏:30
解决时间 2021-01-29 01:35
- 提问者网友:绫月
- 2021-01-28 08:07
stringgrid的字同一列字如何换行
最佳答案
- 二级知识专家网友:白昼之月
- 2021-01-28 08:41
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var{这个DrawCell里的代码是老冯写的}
HCell: Integer;
HRow: Integer;
SCell: string;
begin
with TStringGrid(Sender) do begin
SCell := Cells[ACol, ARow];
HRow := RowHeights[ARow];
Canvas.FillRect(Rect);
HCell := DrawText(Canvas.Handle, PChar(SCell), Length(SCell), Rect, DT_Center or DT_VCenter or DT_WORDBREAK );
if HCell > HRow then RowHeights[ARow] := HCell;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goAlwaysShowEditor];
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
with TStringGrid(Sender) do
if Key=#13 then begin
Cells[Col,Row] := Cells[Col,Row]+#13+#10;
Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goAlwaysShowEditor];
end;
end;
Rect: TRect; State: TGridDrawState);
var{这个DrawCell里的代码是老冯写的}
HCell: Integer;
HRow: Integer;
SCell: string;
begin
with TStringGrid(Sender) do begin
SCell := Cells[ACol, ARow];
HRow := RowHeights[ARow];
Canvas.FillRect(Rect);
HCell := DrawText(Canvas.Handle, PChar(SCell), Length(SCell), Rect, DT_Center or DT_VCenter or DT_WORDBREAK );
if HCell > HRow then RowHeights[ARow] := HCell;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goAlwaysShowEditor];
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
with TStringGrid(Sender) do
if Key=#13 then begin
Cells[Col,Row] := Cells[Col,Row]+#13+#10;
Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goAlwaysShowEditor];
end;
end;
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯