问题描述
我正在尝试基于 TComboBox 类实现自定义控件。下面的代码可以编译,但从未调用 OnDrawItem (MyDrawItem)。我做错了什么?
unit TLocalizedComboBox_unit;
interface
uses
System.SysUtils,System.Classes,Vcl.Controls,Vcl.StdCtrls,System.Types;
type
TLocalizedComboBox = class(TComboBox)
private
{ Private declarations }
protected
{ Protected declarations }
published
{ Published declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
procedure MyDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
end;
procedure Register;
implementation
constructor TLocalizedComboBox.Create(AOwner: TComponent);
begin
Style := csOwnerDrawFixed;
OnDrawItem := Self.MyDrawItem;
inherited Create(AOwner);
end;
procedure TLocalizedComboBox.MyDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
Canvas.TextRect(Rect,Rect.Left,Rect.Top,Items.Names[Index]);
end;
procedure Register;
begin
RegisterComponents('MyProjectsComponents',[TLocalizedComboBox]);
end;
end.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)