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
相关产品推荐
相关产品推荐

