如何从我的form2
群组盒无线电按钮(3个无线电按钮,我只能显示一个)在我的Form1
文本框中显示选定的项目。
这是我的问题,因为我只知道要显示的代码。如果状态不工作的话。
Form1:
public void button5_Click(object sender, EventArgs e)
{
Form2 fr2 = new Form2();
textBox1.Text = fr2.receivet(textBox1.Text, fr2.radioButton1);
}
Form2:
internal string receivet(string textBox1, RadioButton radio)
{
return textBox1 = radio.Text;
}
发布于 2022-10-23 19:01:11
不需要创建方式,您可以直接从表单对象中获取RadioButton。
public void button5_Click(object sender, EventArgs e)
{
Form2 fr2 = new Form2();
string radioTxt = ""
if (fr2.RadioButton1.Checked)
{
radioTxt = fr2.RadioButton1.Text
}
else if (fr2.RadioButton2.Checked)
{
radioTxt = fr2.RadioButton2.Text
}
else if (fr2.RadioButton3.Checked)
{
radioTxt = fr2.RadioButton3.Text
}
textBox1.Text = radioTxt;
}
发布于 2022-10-23 18:45:35
在您的代码中,您将创建一个新的Form2实例并接受它的值。您需要调用显示的Form2实例的函数(并将其设置为公共修饰符)。
https://stackoverflow.com/questions/74173749
复制相似问题