首页  编辑  

如何禁止一个控件而不变灰?

Tags: /超级猛料/VCL/用户接口(界面)/   Date Created:
禁止一个按钮而不变灰
请参考下面的代码:
procedure EnableControl(AControl: TWinControl; Enable: Boolean);
begin
  with AControl do
    if Enable then
      SetWindowLong(Handle, GWL_STYLE, (not WS_DISABLED) and
        GetWindowLong(Handle, GWL_STYLE))
    else
      SetWindowLong(Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(Handle,
        GWL_STYLE));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EnableControl(BitBtn1, False);
  BitBtn1.Font.Color := clGreen;
end;