如何使用csOwnerDrawFixed Style的组合框可以像csDropDown样式一样运行? [英] How a Combobox with the csOwnerDrawFixed Style can behave like the csDropDown style?

查看:821
本文介绍了如何使用csOwnerDrawFixed Style的组合框可以像csDropDown样式一样运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有style属性的 TComboBox 组件设置为 csOwnerDrawFixed ,我实现了OnDrawItem ,并且一切都正常,现在我想要使用这种组合框,当具有 csDropDown 样式(与csOwnerDrawFixed样式的行为类似于csDropDownList样式),我的意思是使用内部编辑器。这可能吗?

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 combobox to behave like when had the csDropDown style (with the csOwnerDrawFixed style behaves like the csDropDownList style) , I mean with a inner editor. is this possible?

推荐答案

Delphi的TComboBox包装器不支持所有者绘制可编辑样式,但底层的Windows控件是,并且很容易启用

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;

样式设置为 csDropDown 并分配 OnDrawItem ,就像你已经在做的那样。

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

这篇关于如何使用csOwnerDrawFixed Style的组合框可以像csDropDown样式一样运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆