首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从另一个窗体在文本框中显示选定的单选按钮

从另一个窗体在文本框中显示选定的单选按钮
EN

Stack Overflow用户
提问于 2022-10-23 18:31:10
回答 2查看 56关注 0票数 -1

如何从我的form2群组盒无线电按钮(3个无线电按钮,我只能显示一个)在我的Form1文本框中显示选定的项目。

这是我的问题,因为我只知道要显示的代码。如果状态不工作的话。

Form1:

代码语言:javascript
运行
复制
public void button5_Click(object sender, EventArgs e)
{    
    Form2 fr2 = new Form2();
    textBox1.Text = fr2.receivet(textBox1.Text, fr2.radioButton1);
    
}

Form2:

代码语言:javascript
运行
复制
internal string receivet(string textBox1, RadioButton radio)
{
    return textBox1 = radio.Text;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-10-23 19:01:11

不需要创建方式,您可以直接从表单对象中获取RadioButton。

代码语言:javascript
运行
复制
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;

}
票数 1
EN

Stack Overflow用户

发布于 2022-10-23 18:45:35

在您的代码中,您将创建一个新的Form2实例并接受它的值。您需要调用显示的Form2实例的函数(并将其设置为公共修饰符)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74173749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档