【发布时间】:2011-11-30 14:22:22
【问题描述】:
我在表单上有一个TGridPanel,并希望将控件添加到单击的特定“单元格”。
我很容易明白这一点:
procedure TForm1.GridPanel1DblClick(Sender: TObject);
var
P : TPoint;
InsCol, InsRow : Integer;
begin
P := (Sender as TGridPanel).ScreenToClient(Mouse.CursorPos);
if (Sender as TGridPanel).ControlAtPos(P) = nil then
begin
InsCol := ???;
InsRow := ???;
(Sender as TGridPanel).ControlCollection.AddControl(MyControl, InsCol, InsRow)
end;
end;
我可能不需要if ControlAtPos(P) = nil then 行,但我想确保我没有在已包含控件的单元格中插入控件。
那么...我使用什么代码来获取 InsCol 和 InsRow?我一直在 TGridPanel 和 TControlCollection 类代码上下移动,找不到任何可以从鼠标坐标中给我列或行值的东西。除了OnDblClick()之外,它们似乎也不是可以使用的相关事件。
任何帮助将不胜感激。
编辑:将变量 Result 更改为 MyControl 以避免混淆。
【问题讨论】:
标签: delphi delphi-2007 tgridpanel