在stringgrid里如何把一个控件嵌入cell里

zhmf 2002-07-17 11:56:23
在stringgrid里如何把一个控件嵌入cell里

如:把一个edit放到stringgrid的cell[2,1]
...全文
53 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sean2000 2002-07-17
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages,stdctrls, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public

end;

var
Form1: TForm1;
i,j:integer;
var testcombo:Tcombobox;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
testcombo:=Tcombobox.create(self);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
testcombo.Free;
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
i:=x div stringgrid1.defaultcolwidth;
j:=y div stringgrid1.defaultrowheight;
testcombo.parent:=self;
testcombo.left:=stringgrid1.left+i*(stringgrid1.defaultcolwidth+2);
testcombo.top:=stringgrid1.top+j*(stringgrid1.defaultrowheight+2);
testcombo.width:=stringgrid1.DefaultColWidth;
testcombo.Height:=stringgrid1.gridHeight;
testcombo.font:=stringgrid1.font;
testcombo.Items.Clear;
testcombo.text:='未知';
testcombo.Items.add('1111');
testcombo.Items.add('2222');
testcombo.Items.add('3333');
testcombo.Items.add('4444');
end;

end.
netlib 2002-07-17
  • 打赏
  • 举报
回复
动态或静态创建一个,
运行时候调整它的parent、top、left、visibled来决定是否显示以及显示的位置。

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧