我的界面上有2个ComboBox控件,一个ToolButton按钮,一个RadioGroup1单选框。这个过程我是这么设计的:
只有当ComboBox我都输入内容并且RadioGroup1我选择了后,我才希望ToolButton确定,否则ToolButton按钮是灰色的,就是不能按下去。
这个功能我不想在ToolButton按钮下实现,想在ComboBox和RadioGroup1下实现,请问在哪里触发事件,该怎么编,谢谢!

解决方案 »

  1.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        ComboBox2: TComboBox;
        ToolBar1: TToolBar;
        ToolButton1: TToolButton;
        RadioGroup1: TRadioGroup;
        Label1: TLabel;
        procedure ComboBox1Change(Sender: TObject);
        procedure ComboBox2Change(Sender: TObject);
        procedure RadioGroup1Click(Sender: TObject);
      private
        { Private declarations }
        function CheckCanUseButton(cmb1, cmb2: TComboBox; rg: TRadioGroup): Boolean;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}function TForm1.CheckCanUseButton(cmb1, cmb2: TComboBox; rg: TRadioGroup): Boolean;
    begin
      Result := (cmb1.Text <> '') and (cmb2.Text <> '') and (rg.ItemIndex <> -1);
    end;procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
      ToolButton1.Enabled := CheckCanUseButton(ComboBox1, ComboBox2, RadioGroup1);
    end;procedure TForm1.ComboBox2Change(Sender: TObject);
    begin
      ToolButton1.Enabled := CheckCanUseButton(ComboBox1, ComboBox2, RadioGroup1);
    end;procedure TForm1.RadioGroup1Click(Sender: TObject);
    begin
      ToolButton1.Enabled := CheckCanUseButton(ComboBox1, ComboBox2, RadioGroup1);
    end;end.
      

  2.   

    在ComboBox的OnChange事件里检测ComboBox.text和RadioGroup.itemindex
    在RadioGroup的OnClick事件里检测ComboBox.text和RadioGroup.itemindex
    两个事件里写的判断都是一样:if (ComboBox.text <> '') and (RadioGroup.itemindex <> -1) then
      ToolButton.Enable := True
    else
      ToolButton.Enable := False;