将值从一种形式设置为另一种形式? [英] Setting values from one form to another?
本文介绍了将值从一种形式设置为另一种形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从FORM_1的局部变量ID设置FORM_2中的标签值?
解决方案
Form1按钮事件
public string kmp = ;
private void Button_Click( object sender,EventArgs e)
{
Form2 qu = new Form2();
qu.ShowDialog();
lable.text = kmp;
}
Form2按钮事件
private void Button_Click( object sender,EventArgs e)
{
Form1 l = new Form1();
l.kmp = textbox.text;
}
在表格2上创建一个属性
< pre lang =cs> public string LblText
{
set {lable.text = value ;}
}
并从Form1(在显示对话框之前)设置此属性值
public Int kmp = 0 ;
private void Button_Click( object sender,EventArgs e)
{
kmp = ur value ;
Form2 qu = new Form2();
qu.ShowDialog();
}
private void Form2_Load( object sender,EventArgs e)
{
Form1 l = new Form1();
label1.text = l.kmp.toString();
}
或
private void Button_Click( object sender,EventArgs e)
{
Form2 qu = new Form2(ur value 跨度>);
qu.ShowDialog();
}
public Form2( int l)
{
InitializeComponent();
label1.text = l.toString();
}
how to set value of a label in FORM_2 from the local variable ID from FORM_1?
解决方案Form1 button event
public string kmp=""; private void Button_Click(object sender, EventArgs e) { Form2 qu = new Form2 (); qu.ShowDialog(); lable.text =kmp; }
Form2 button event
private void Button_Click(object sender, EventArgs e) { Form1 l = new Form1(); l.kmp = textbox.text; }
Create a property on Form 2
public string LblText { set { lable.text = value ;} }
and set value to this property from Form1 (before show dialog)
public Int kmp=0; private void Button_Click(object sender, EventArgs e) { kmp=ur value; Form2 qu = new Form2 (); qu.ShowDialog(); }
private void Form2_Load(object sender, EventArgs e) { Form1 l = new Form1(); label1.text= l.kmp.toString() ; }
Or
private void Button_Click(object sender, EventArgs e) { Form2 qu = new Form2 (ur value); qu.ShowDialog(); }
public Form2(int l) { InitializeComponent(); label1.text=l.toString(); }
这篇关于将值从一种形式设置为另一种形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文