Blurry Sterk
Blurry Sterk

Reputation: 1607

Prevent control animation when setting RadioButton.Checked

I set two radiobuttons' Checked property on a second form before showing that form. Each time the button is clicked to set the Checked properties and show the form I invert ("NOT") the Checked for each radiobutton. Then upon showing the form one clearly can see the animation (Checked properties being changed) of the radiobuttons happening. It does not happen on first run but happens on each subsequent show of the form.

I would like to prevent the animation and just have the radiobuttons show the newly set checked state when the form is shown. Is there a way to do it?

Having the radiobuttons on a disabled panel or making them invisible before setting the Checked does not work.

enter image description here

Form1:

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.RadioButton1.Checked := not Form2.RadioButton1.Checked;
  Form2.RadioButton2.Checked := not Form2.RadioButton1.Checked;

  Form2.Show;
end;

Form1 DFM:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 81
  ClientWidth = 249
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 36
    Top = 24
    Width = 157
    Height = 25
    Caption = 'Set Radios and Show Form2'
    TabOrder = 0
    OnClick = Button1Click
  end
end

Form2:

type
  TForm2 = class(TForm)
    Button1: TButton;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  Hide;
end;

end.

Form2 DFM:

object Form2: TForm2
  Left = 0
  Top = 0
  Caption = 'Form2'
  ClientHeight = 131
  ClientWidth = 176
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 44
    Top = 90
    Width = 75
    Height = 25
    Caption = 'Hide'
    TabOrder = 0
    OnClick = Button1Click
  end
  object RadioButton1: TRadioButton
    Left = 38
    Top = 20
    Width = 113
    Height = 17
    Caption = 'RadioButton1'
    TabOrder = 1
  end
  object RadioButton2: TRadioButton
    Left = 38
    Top = 44
    Width = 113
    Height = 17
    Caption = 'RadioButton2'
    TabOrder = 2
  end
end

Upvotes: 1

Views: 364

Answers (1)

Tom Brunberg
Tom Brunberg

Reputation: 21033

Set the DoubleBuffered property of the TRadioButtons to True.

Upvotes: 1

Related Questions