2016-02-14 41 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