关键是使用 FEditHandle域:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyComboBox = class(TComboBox)
private
FReadOnly:Boolean;
procedure SetReadOnly(Value:Boolean);
protected
procedure Createwnd;override;
published
property ReadOnly:Boolean Read FReadOnly write SetReadOnly;
end;
implementation
procedure TMyComboBox.SetReadOnly(value:Boolean);
begin
if FReadOnly <> Value then
begin
FReadOnly := Value;
if FEditHandle > 0 then
SendMessage(FEditHandle, EM_SETREADONLY, Ord(Value), 0);
end;
end;
procedure TMyComboBox.CreateWnd;
begin
inherited CreateWnd;
if FEditHandle > 0 then
SendMessage(FEditHandle, EM_SETREADONLY, Ord(FReadOnly), 0);
end;
end.