【问题标题】:How can I make a SearchBox visible when I open the list of a ComboBox in Delphi在 Delphi 中打开 ComboBox 列表时如何使 SearchBox 可见
【发布时间】:2015-11-17 10:29:49
【问题描述】:

我正在使用 Delphi 10 Seattle 创建多设备软件 (Win32) (Firemonkey)。 仅当列表显示在 ComboBox 中时,如何显示 SearchBox。 我用 ListBoxItems 在代码中填充 ComboBox。请参阅下面的示例。 现在 SearchBox 显示在关闭的 ComboBox 上。

procedure AddItems;
var
  SearchBox: TSearchBox;
  Item: TListBoxItem;
begin
  ComboBox.Items.Clear;
  SearchBox := TSearchBox.Create(ComboBox);
  SearchBox.Align := TAlignLayout.Contents;
  SearchBox.Parent := ComboBox;
  SearchBox.Visible:=True;
  Item := TListBoxItem.Create(ComboBox);
  Item.Parent := ComboBox;
  Item.Text := 'Item 1';
  Item := TListBoxItem.Create(ComboBox);
  Item.Parent := ComboBox;
  Item.Text := 'Item 2';
end;

【问题讨论】:

    标签: delphi combobox firemonkey search-box


    【解决方案1】:

    使用 TComboBox 事件OnPopup & OnClosePopup

    将 ScrollBox 声明移动到私有表单(或框架)部分并在OnCreate 表单事件(或框架构造函数)中创建它。

    type
      THeaderFooterForm = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        FSearchBox: TSearchBox;
      end;
    
    procedure THeaderFooterForm.FormCreate(Sender: TObject);
    begin
      FSearchBox := TSearchBox.Create(nil);
      FSearchBox.Align := TAlignLayout.Contents;
      FSearchBox.Parent := ComboBox;
      FSearchBox.Visible:=False;
    end;
    
    procedure THeaderFooterForm.ComboBoxClosePopup(Sender: TObject);
    begin
      FSearchBox.Visible:=False;
    end;
    
    procedure THeaderFooterForm.ComboBoxPopup(Sender: TObject);
    begin
      FSearchBox.Visible:=True;
    end;
    

    【讨论】:

    • 谢谢kami,但是当我选择搜索框输入一些文本时,列表关闭。期望的行为是缩小列表中的项目范围。
    • 我的错。我没有想到。当 SearchBox 获得焦点时,您无法阻止关闭弹出窗口(弹出窗口由 TScreen.ClosePopupForms 关闭)。此外,如果您将 SearchBox 放在 ComboBox.Popup 的顶部,则无法获得输入值的焦点...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    相关资源
    最近更新 更多