将表单的值传输到用户控件 [英] Transfer value of Form to Usercontrol

查看:25
本文介绍了将表单的值传输到用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用户控件并向其添加了一个文本框.在我的 Windows 窗体中,我添加了我创建的用户控件并添加了一个文本框和一个按钮.如何将我从Form的文本框输入的文本复制到Usercontrol的文本框,反之亦然.就像是usercontrol.textBox1.text = textBox1.text

I create a user control and add a textbox to it. In my windows form I add the user control i created and add a textbox and a button. How to copy the text I input from the textbox of Form to textbox of Usercontrol and vice versa. Something like usercontrol.textBox1.text = textBox1.text

推荐答案

从表单到用户控件

Form Code
public string ID
{
    get { return textBox1.Text; }
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
    userControl11.ID = ID;
}

Usercontrol Code
public string ID
{
    set { textBox1.Text = value; }
}

这篇关于将表单的值传输到用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆