5,402
社区成员
发帖
与我相关
我的任务
分享
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;