我正在尝试基于Delphi 2007中的TCustomComboBox创建一个自定义控件,但我陷入了第一个障碍.
我试图覆盖下拉显示的方式,主要是显示的文本,查看stdctrls.pas中的TCustomComboBox的源代码看起来我只需要覆盖DrawItem但它不起作用,因为我的代码永远不会执行重写方法.
我看了几个开源组件源代码,看看他们是如何做到的,但我仍然不知所措.
这是我到目前为止(不是很多)
type
TKeyValueComboBox = class(TCustomComboBox)
private
{ Private declarations }
//FColumns:Integer;
protected
{ Protected declarations }
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
end;
Run Code Online (Sandbox Code Playgroud)
和
procedure TKeyValueComboBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
begin
TControlCanvas(Canvas).UpdateTextFlags;
if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State)
else
begin
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]+'-HELLO');
end;
end;
Run Code Online (Sandbox Code Playgroud)
有谁知道我需要用什么方法来获取我被覆盖的版本的火?或者我做错了什么?
任何帮助,将不胜感激.