写一个控件嘛:
///////////////////////////////////////////////////////////////////////////////
unit ComboBoxEx;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Messages;
type
TComboBoxEx = class(TComboBox)
private
{ Private declarations }
FOnSetFocus: TNotifyEvent;
FOnKillFocus: TNotifyEvent;
procedure WMSetFocus(var Message: TWMSetFocus)
message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMKillFocus)
message WM_KILLFOCUS;
procedure SetOnKillFocus(const Value: TNotifyEvent);
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
// ComboBox 获得焦点时触发的事件
property OnSetFocus: TNotifyEvent read FOnSetFocus write FOnSetFocus;
// ComboBox 失去焦点时触发的事件
property OnKillFocus: TNotifyEvent read FOnKillFocus write SetOnKillFocus;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('LYF', [TComboBoxEx]);
end;
{ TComboBoxEx }
procedure TComboBoxEx.SetOnKillFocus(const Value: TNotifyEvent);
begin
FOnKillFocus := Value;
end;
procedure TComboBoxEx.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if Assigned(FOnSetFocus) then FOnSetFocus(Self);
end;
procedure TComboBoxEx.WMSetFocus(var Message: TWMSetFocus);
begin
inherited;
if Assigned(FOnKillFocus) then FOnKillFocus(Self);
end;
end.
///////////////////////////////////////////////////////////////////////////////