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);
}
} 展开
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);
}
} 展开
展开全部
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;
}
}
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;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询