如何将值从我的mainform传递给我的usercontrol [英] How to pass Value from my mainform to my usercontrol
本文介绍了如何将值从我的mainform传递给我的usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单中有用户控制(按钮)
在我的usercontrol中。我有这个代码..
public UserControl1()
{
InitializeComponent();
}
public string branch {< span class =code-keyword> get ; set ; }
private void button1_Click( object sender,EventArgs e)
{
MessageBox.Show(branch + 跨度>);
}
和我的表格
private void Form2_Load( object sender,EventArgs e)
{
UserControl1 usr = new 的UserControl1();
usr.branch = Boom;
}
问题:当我点击我的usrctrl按钮时形成。弹出消息是空的。 XD。我不知道为什么。我错过了什么?
解决方案
该死的。我解决了自己的问题:(
我不应该为我的usercontrol创建一个新对象。而是直接调用它。
string str = textBox1.Text;
userControl11.branch = str;
现在它的工作:)
hello guys.! I'm having hard time here trying to solve this problem.
I Have a Userctrl(button)inside a form
In my usercontrol. i have this code..
public UserControl1()
{
InitializeComponent();
}
public string branch { get; set; }
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(branch + "");
}
and in my FORM
private void Form2_Load(object sender, EventArgs e)
{
UserControl1 usr = new UserControl1();
usr.branch= "Boom";
}
PROBLEM : When i hit the usrctrl button in my form. The popup msg is empty. XD. I don't know why. did i missed something?
解决方案
damn. I solved my own question :(
I just should not make an new object for my usercontrol. instead call it directly.
string str = textBox1.Text; userControl11.branch = str;
Now its working :)
这篇关于如何将值从我的mainform传递给我的usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文