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

后端 未结 2 1094
礼貌的吻别
礼貌的吻别 2021-02-15 15:49

I\'m using a TComboBox component with the style property set to csOwnerDrawFixed, I implement the OnDrawItem And everything works fine, Now I want which the co

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-15 16:13

    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.

提交回复
热议问题