我试图在Delphi2007中创建一个基于tcustomcombobox的自定义控件,但是我遇到了第一个障碍。
我试图覆盖下拉列表的显示方式,主要是显示的文本,在stdctrls.pas中查看tcustomcombobox的源代码,看起来我只是需要覆盖drawitem,但它不起作用,因为我覆盖方法中的代码从未执行过。
我已经查看了几个开源组件的源代码,以了解它们是如何做到的,但是我仍然很困惑。
这是我到目前为止所拥有的(不必多说)
type
TKeyValueComboBox = class(TCustomComboBox)
private
{ Private declarations }
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;
和
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;
有人知道我需要使用什么方法来获取我重写的fire版本吗?或者我做错了什么?
任何帮助都将不胜感激。