How a Combobox with the csOwnerDrawFixed Style can behave like the csDropDown style?

和自甴很熟 提交于 2019-12-03 12:53:47

Delphi's TComboBox wrapper doesn't support an owner draw editable style, but the underlying Windows control does, and it's easy to enable it.

Create a new descendant class like so:

TComboBox = class(StdCtrls.TComboBox)
public
  procedure CreateParams(var Params: TCreateParams); override;
end;

procedure TComboBox.CreateParams(var Params: TCreateParams);
begin
  inherited;
  if Assigned(OnDrawItem) then
    Params.Style := Params.Style or CBS_OWNERDRAWFIXED
end;

Set the Style to csDropDown and assign OnDrawItem like you're already doing.

None of the OwnerDraw styles support the presence of an edit box in the TComboBox. You will have to use a separate TEdit instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!