c++ Radiobutton

来源:百度知道 编辑:UC知道 时间:2024/05/02 16:52:04
初学c++,想写个计算器 使用 radiobutton 的
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{

int a,b;
a=this->Edit1->Text.ToInt();
b=this->Edit2->Text.ToInt();
if (this->RadioButton1->);
this->Edit3->Text=a+b ;

else if (this->RadioButton2->Checked);
this->Edit3->Text=a-b ;
/*
if (this->RadioButton3->OnClick)
this->Edit3->Text=a*b ;
if (this->RadioButton4->OnClick)
this->Edit3->Text=a/b ;
*/
}
//---------------------------------------------------------------------------
已上是部分代码。。相信您也知道我的目的了 if (this->RadioButton1->这里应该用哪个是指被选定呢);
还有为什么这里用else if 会显示Code has no effect?
//---------------------
请问 if (this->RadioButton1->这里接什么是指被选定呢)
谢谢回答

int a,b;
a=this->Edit1->Text.ToInt();
b=this->Edit2->Text.ToInt();
if (this->RadioButton1->);
/////////////////
注意这里的分号“;”去掉。

否则会被认为
if (*****)
{
;
}
……

回答补充:
我理解你的源码是
两个数据的加减运算方式的选择。
BC我记不清了,
但道理肯定是这样的。

if (radio1->checked)
{
……
}
else if (radio2->checked)
{
……
}

所以,按照你下边的radio2,理解

if (this->RadioButton1->这里接什么是指radiobutton1被选中
可以查看radiobutton1的属性中的“checked”一项。

仅供参考。