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

Delphi 11.3 FMX如何自定义Combobox下拉列表背景(透明+圆角)

Delphi 11.3 FMX 实现带圆角的透明下拉列表Combobox

一、给Combobox本体添加圆角

不用嵌套矩形,直接通过定制样式实现:

  • 右键Combobox选择Edit Custom Style,进入样式编辑器
  • 找到样式内的Background矩形,设置CornerRadius为目标数值(如8),Fill.Color设为claNull(透明)
  • 找到Edit控件,将其Background.Fill.Color也设为claNull,避免输入框背景遮挡圆角效果
  • 调整Border矩形的CornerRadius和Stroke.Color,保持与整体圆角风格一致

二、定制下拉列表(PopupListBox)的透明+圆角样式

FMX的Combobox下拉列表是动态创建的TPopupListBox,需单独定制样式:

  1. 在窗体上临时添加一个TListBox,右键选择Edit Custom Style进入样式编辑器
  2. 在样式内:
    • 找到Background矩形,设置Fill.Color为claNull,CornerRadius设为与Combobox一致的数值
    • 找到ListBoxItemStyle内的Background,同样将Fill.Color设为claNull,确保列表项背景透明
    • 若需要列表项带圆角,调整ListBoxItemStyle内Border矩形的CornerRadius
  3. 将这个定制好的样式命名为CustomPopupListBoxStyle(在样式编辑器的StyleName字段修改),然后删除临时的TListBox
  4. 给Combobox添加OnDropDown事件,动态绑定自定义样式:
procedure TForm1.ComboBox1DropDown(Sender: TObject);
var
  PopupList: TPopupListBox;
begin
  if Sender is TCustomComboBox then
  begin
    PopupList := TCustomComboBox(Sender).PopupListBox;
    if Assigned(PopupList) then
      PopupList.StyleLookup := 'CustomPopupListBoxStyle';
  end;
end;

三、避免无效操作的关键注意事项

  • 确保StyleBook已关联到窗体或Combobox,否则自定义样式无法生效
  • Delphi 11.3中TPopupListBox是动态创建的,直接在Object Inspector里设置Combobox的PopupListBox.StyleLookup不会生效,必须通过OnDropDown事件动态绑定
  • 若之前按博客方法未生效,大概率是没做动态样式绑定这一步,或者样式未正确保存到StyleBook中
  • 测试时建议用带图案的窗体背景,这样透明效果会更直观

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 07:42:47