Change CheckBox state without calling OnClick Event

后端 未结 8 1774
时光取名叫无心
时光取名叫无心 2021-01-04 06:35

I\'m wondering so when I change state of CheckBox

CheckBox->Checked=false;

It calls CheckBoxOnClick Event , how to avoid it ?

8条回答
  •  余生分开走
    2021-01-04 06:53

    Another option is to change the protected ClicksDisable property using an interposer class like this:

    type
      THackCheckBox = class(TCustomCheckBox)
      end;
    
    procedure TCheckBox_SetCheckedNoOnClick(_Chk: TCustomCheckBox; _Checked: boolean);
    var
      Chk: THackCheckBox;
    begin
      Chk := THackCheckBox(_Chk);
      Chk.ClicksDisabled := true;
      try
        Chk.Checked := _Checked;
      finally
        Chk.ClicksDisabled := false;
      end;
    end;
    

提交回复
热议问题