【发布时间】:2015-12-03 20:52:08
【问题描述】:
我在西雅图工作,为 Windows 编写一个 FM 应用程序。
我的表单上有一个 tlistview 并填充了数据。
我打开了搜索选项。
如何以编程方式将焦点设置到搜索框?
如何增加搜索框的大小和字体大小?
谢谢
【问题讨论】:
标签: delphi firemonkey delphi-10-seattle tlistview
我在西雅图工作,为 Windows 编写一个 FM 应用程序。
我的表单上有一个 tlistview 并填充了数据。
我打开了搜索选项。
如何以编程方式将焦点设置到搜索框?
如何增加搜索框的大小和字体大小?
谢谢
【问题讨论】:
标签: delphi firemonkey delphi-10-seattle tlistview
搜索框不应以编程方式访问,除非将其设置为可见并在更改时触发事件。否则,它只能由用户访问。
因此,访问有点涉及。然而,OnSearchChange 事件的example 激发了以下答案:
uses ..., FMX.SearchBox;
type
TForm17 = class(TForm)
ListView1: TListView;
Button1: TButton;
Label1: TLabel;
...
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
sb: TSearchBox; // a local reference
...
end;
implementation
procedure TForm17.Button1Click(Sender: TObject);
begin
if Assigned(sb) then
sb.SetFocus;
end;
procedure TForm17.FormCreate(Sender: TObject);
var
i: integer;
begin
ListView1.SearchVisible := True; // or set in the Object Inspector at design time
for i := 0 to ListView1.Controls.Count-1 do
if ListView1.Controls[I].ClassType = TSearchBox then
begin
sb := TSearchBox(ListView1.Controls[i]);
Break;
end;
end;
procedure TForm17.ListView1SearchChange(Sender: TObject);
begin
if Assigned(sb) then
Label1.Text := sb.Text;
end;
在创建表单时,我们搜索 SearchBox 控件,如果找到,我们将对其的引用存储在 sb: TSearchBox; 字段中。那么访问就很简单了。
【讨论】: