You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FireMonkey TComboColorBox:选色后如何通过代码隐藏颜色选择器?

在FireMonkey中编程隐藏TComboColorBox的颜色选择器

FireMonkey的TComboColorBox本身没有直接暴露关闭下拉选择器的公共方法,但可以通过类助手访问它的保护成员来实现需求,具体步骤如下:

  • 定义类助手,突破访问限制调用内部弹窗控件:

    type
      TComboColorBoxHelper = class helper for TComboColorBox
      public
        procedure HideColorPopup;
      end;
    
    procedure TComboColorBoxHelper.HideColorPopup;
    begin
      // 检查弹窗是否存在且可见,再执行隐藏
      if Assigned(Popup) and Popup.Visible then
        Popup.Hide;
    end;
    
  • 在颜色选择完成的事件中调用该方法,比如OnChange事件:

    procedure TYourForm.ComboColorBox1Change(Sender: TObject);
    begin
      // 选择颜色后立即隐藏下拉选择器
      TComboColorBox(Sender).HideColorPopup;
    end;
    

原理说明:TComboColorBox继承自TComboBox,其颜色选择器本质是内部的TPopup控件,通过类助手可以访问原本受保护的Popup属性,直接调用Hide方法即可关闭下拉面板。

内容的提问来源于stack exchange,提问作者user2383818

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 23:25:58