2016-02-14 42 views
1

在显示该窗体之前,我在第二个窗体上设置了两个单选按钮的Checked属性。每次单击该按钮以设置“检查”属性并显示表格I时,对每个单选按钮反转(“NOT”)检查。然后,在显示表单之后,可以清楚地看到发生的单选按钮的动画(被更改的选中属性)。它不会在第一次运行时发生,但会在每次后续的表单显示中发生。设置RadioButton.Checked时防止控制动画

我想阻止动画,只是在显示窗体时让单选按钮显示新设置的检查状态。有没有办法做到这一点?

在禁用的面板上放置单选按钮或在设置“检查”之前使它们不可见,不起作用。

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 

窗体2:

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. 

窗体2 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 
+0

你为什么要以这种方式检查和取消选中你的电台按钮?你知道单选按钮的目的是简单地检查一个,而其余的将被自动取消选中。但是由于你的代码已经手动执行了这个操作,所以你可能想用你的复选框替换你的这些单选按钮。你已经有了代码来切换它们之间的检查状态。与单选按钮不同的复选框没有任何动画。 – SilverWarior

+0

该代码是一个实验,绝不是项目的一部分,也不是我在项目中使用的东西。它设置了看动画是如何运作的,这就是我偶然发现的。我想知道是否有某种解决方法来解决“问题” –

+0

我认为这是为什么我只发表评论。任何方式,我不认为这是完全可以禁用单选按钮动画,因为它似乎只是一个共同的双赢控制包装。因此控制它是否是动画是由Windows自己完成的。 – SilverWarior

回答

1

TRadioButtonDoubleBuffered属性设置为True

+0

将DoubleBuffered设置为true确实会阻止动画。不幸的是,总是阻止动画。所以要解决这个问题,只要我点击一个单选按钮,当我显示窗体并将其设置为false时,就将其设置为true。你的建议可以让我做到这一点,接受答案。谢谢 –

+0

相当粗暴的矫枉过正! –

+0

将DoubleBuffered设置为true不会阻止动画,它只会使动画更快发生,因此不太明显。 – SilverWarior