首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

StringGrid编辑状态怎么让文字换行

2012-04-04 
StringGrid编辑状态如何让文字换行直接打回车就变成编辑完成了,还请指点[解决办法]1、如果楼主的意图是“在

StringGrid编辑状态如何让文字换行
直接打回车就变成编辑完成了,还请指点

[解决办法]
1、如果楼主的意图是“在某一格里输入回车键,则退出编辑状态”:

只需把StringGrid的Options设置为[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing]即可

注意,仅是比默认设置多了一个goEditing

---------------------------------

2、如果楼主的意图是“在某一格里输入回车键,则该格文本换行继续输入”:

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];
Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing,goAlwaysShowEditor];
end;
end;

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, 0 );
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;
//楼主可以在某一格里输入一行文本,然后打回车再输入一行,然后把焦点移至其他格子看一下

热点排行