C#winform应用程序怎样将数据发送到led显示屏解决方法
1个回答
展开全部
假设:
Form1为父窗体(包含textBox1、button1)
Form2为子窗体(包含textBox2、button2)
方法:
点击Form1的button1 打开Form2,再点击Form2的button2;在button2_Click事件中,通过this.Owner及调用父窗体Form1的公开属性或方法将Form2的textBox2的值设置给Form1的textBox1,关闭Form2。
代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public string TextBox1Text
{
set { this.textBox1.Text = value; }
get { return this.textBox1.Text; }
} private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show(this);//或 frm2.ShowDialog(this); ////或者
//Form2 frm2 = new Form2();
//frm2.Owner = this;
//frm2.Show();//或 frm2.ShowDialog();
}
} public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
Form1 frm1 = (Form1)this.Owner;
frm1.TextBox1Text = this.textBox2.Text;
this.Close();
}
}
Form1为父窗体(包含textBox1、button1)
Form2为子窗体(包含textBox2、button2)
方法:
点击Form1的button1 打开Form2,再点击Form2的button2;在button2_Click事件中,通过this.Owner及调用父窗体Form1的公开属性或方法将Form2的textBox2的值设置给Form1的textBox1,关闭Form2。
代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public string TextBox1Text
{
set { this.textBox1.Text = value; }
get { return this.textBox1.Text; }
} private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show(this);//或 frm2.ShowDialog(this); ////或者
//Form2 frm2 = new Form2();
//frm2.Owner = this;
//frm2.Show();//或 frm2.ShowDialog();
}
} public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
Form1 frm1 = (Form1)this.Owner;
frm1.TextBox1Text = this.textBox2.Text;
this.Close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询