【发布时间】:2018-09-25 22:21:31
【问题描述】:
我想创建一个属性编辑器,因为TValueListEditor 不支持很多东西。因此,当用户输入单元格时,我使用了TStringGrid 和其他控件。当我为布尔值放置 TCheckBox 时,动态创建的 TCheckBox 是不可检查的。 onClick 事件处理程序不会被点击触发(网格触发),TCheckBox 的标题失去了不透明度。我设置它的父级并将它带到前面。此时我也使用了TEdit 和TComboBox 控件,它们工作正常。有人可以帮助以预期的方式使用它吗?
这里有一个例子来重现这种情况。
过去:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids,
StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
CheckBox1: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure onCheckBoxClicked( sender_ : TObject );
public
{ Public declarations }
fCheckBox : TCheckBox;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.onCheckBoxClicked( sender_ : TObject );
begin
if ( TCheckBox( sender_ ).checked ) then
TCheckBox( sender_ ).caption := 'true'
else
TCheckBox( sender_ ).caption := 'false';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
fCheckBox := TCheckBox.create( NIL );
fCheckBox.Parent := stringGrid1;
fCheckBox.caption := 'Dynamic checkbox';
fCheckBox.left := 70;
fCheckBox.top := 30;
fCheckBox.onClick := onCheckBoxClicked;
fCheckBox.BringToFront;
stringgrid1.cells[1,1] := 'fgfgfgfgfgf';
stringgrid1.cells[1,2] := 'fgfgfgfgfgf';
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
fCheckBox.Free;
end;
end.
dfm:
object Form1: TForm1
Left = 358
Top = 183
Caption = 'Form1'
ClientHeight = 601
ClientWidth = 854
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object StringGrid1: TStringGrid
Left = 120
Top = 72
Width = 320
Height = 120
TabOrder = 0
end
object CheckBox1: TCheckBox
Left = 192
Top = 128
Width = 97
Height = 17
Caption = 'Static checkbox'
TabOrder = 1
end
end
【问题讨论】:
-
您究竟需要什么
TValueListEditor无法处理?TStringGrid不是为托管子控件而设计的,除了它自己的就地单元格编辑器。您可能会更幸运,只需使用网格的OnDrawCell事件根据需要将 CheckBox 的 图像 所有者绘制到您的单元格上,然后使用网格的OnMouseDown/Up事件“切换”检查细胞的状态。您可以使用网格的Objects属性来跟踪状态数据。 -
@RemyLebeau 很多东西。可折叠的复合值、活动的内联编辑器(TEdit、TComboBox、TCheckBox 和自定义组件)。我想内联使用很多组件种类。
-
你最好找到一个处理所有这些东西的第三方属性编辑器,并且可以在运行时使用。仅使用默认的 VCL 组件将很难做到这一点。
标签: delphi