我试图在Delphi 2007中基于TCustomComboBox创建一个自定义控件,但我遇到了第一个障碍。
我试图重写下拉菜单的显示方式,主要是显示的文本,查看stdctrls.p中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;
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;
任何帮助都将不胜感激。