单选框在Windows应用程序中到处可见, 比如, 对于一个人来说, 性别只能是男女其一, 此时, 我们可以考虑用单选框(其实, 此时仅仅用一个TCheckBox复选框也可以搞定)。 界面图, 我就不画了, 直接给出代码:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int result = -1;
    if(RadioButton1->Checked)
    {
       result = 1;
    }

    if(RadioButton2->Checked)
    {
       result = 2;
    }

    ShowMessage(result);
}
//---------------------------------------------------------------------------







本文转载:CSDN博客