c++builder中memo和radiobutton的用法

我建立3个form,form1中radiobutton1、radiobutton2和button1;form2中radiobutton3、radiobutton4和but... 我建立3个form,form1中radiobutton1、radiobutton2和button1;form2中radiobutton3、radiobutton4和button2;form3中一个memo。我是想让点击button1时在memo第一行中显示radiobutton1或radiobutton2,点击button2时先时候radiobutton3或radiobutton4的caption。代码如下,运行没有错误。但是用的时候,memo中不是按照我想的显示。请问应该怎么改?

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

if(Form1->RadioButton1->Checked)
{
Form3->Show();
Form3->Memo1->Lines->Delete(1);
Form3->Memo1->Lines->Add(Form1->RadioButton1->Caption);
}
else
if(Form1->RadioButton2->Checked)
{
Form3->Memo1->Lines->Delete(1);
Form3->Memo1->Lines->Add(Form1->RadioButton2->Caption);
}
Form2->Show();
}

/----------------------------------------------------------------------------------
void __fastcall TForm2::Button2Click(TObject *Sender)
{

if(Form2->RadioButton1->Checked)
{
Form3->Memo1->Lines->Delete(2);
//改为Delete(Form3->Memo1->Lines->IndexOf ( Form2->RadioButton2->Caption))也不对
Form3->Memo1->Lines->Add(Form2->RadioButton1->Caption);
}
else
if(Form2->RadioButton2->Checked)
{
Form3->Memo1->Lines->Delete(2);
Form3->Memo1->Lines->Add(Form2->RadioButton2->Caption);
}
}
展开
 我来答
veket的小号
2013-05-27 · TA获得超过3371个赞
知道大有可为答主
回答量:3762
采纳率:0%
帮助的人:3977万
展开全部
Form3->Memo1->Lines->Count 看看 判断下 memo的行数

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(Form1->RadioButton1->Checked)
{
Form3->Show();
if(Form3->Memo1->Lines->Count == 0)//行数为零,没有就加
{
Form3->Memo1->Lines->Add(Form1->RadioButton1->Caption);
}
else//函数不为零,直接改第一行
{
Form3->Memo1->Lines->Strings[0] = Form1->RadioButton1->Caption;
}
}
if(Form1->RadioButton2->Checked)//radiobutton2 同理
{
Form3->Show();
if(Form3->Memo1->Lines->Count == 0)
{
Form3->Memo1->Lines->Add(Form1->RadioButton2->Caption);
}
else
{
Form3->Memo1->Lines->Strings[0] = Form1->RadioButton2->Caption;
}
}
Form2->Show();
}

void __fastcall TForm2::Button1Click(TObject *Sender)
{
if(Form2->RadioButton1->Checked)
{
Form3->Show();
if(Form3->Memo1->Lines->Count == 0)//
{
Form3->Memo1->Lines->Add("");//刷进去个空白行
Form3->Memo1->Lines->Add(Form2->RadioButton1->Caption);//刷到第二行
}
else if(Form3->Memo1->Lines->Count == 1)
{
Form3->Memo1->Lines->Add(Form2->RadioButton1->Caption);//已经有一行了,直接添加 第二行
}
else//大于1行,直接改第二行
{
Form3->Memo1->Lines->Strings[1] = Form2->RadioButton1->Caption;
}
}
if(Form2->RadioButton2->Checked)//同理
{
if(Form3->Memo1->Lines->Count == 0)
{
Form3->Memo1->Lines->Add("");
Form3->Memo1->Lines->Add(Form2->RadioButton2->Caption);
}
else if(Form3->Memo1->Lines->Count == 1)
{
Form3->Memo1->Lines->Add(Form2->RadioButton2->Caption);
}
else
{
Form3->Memo1->Lines->Strings[1] = Form2->RadioButton2->Caption;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式