C# 窗体调用的问题,急求!
怎样在窗体form3的标签lable里显示窗体form1文本框text中的内容,怎样调用??好困惑!求详细代码解释 C#,窗体,调用
[解决办法]
不管什么关系都很好解决的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Broadcasting.setValue(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
Form2 form2 = Form2.showfrom();
form2.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form3 form3 = Form3.showform();
form3.Show();
}
}
public delegate void SetTextValue(object value);
/// <summary>
/// 广播类
/// </summary>
public class Broadcasting
{
//event
public static SetTextValue setTextValue;
public static void setValue( object value)
{
if (setTextValue != null)
{
setTextValue(value);
}
}
}
}
[解决办法]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public static Form2 form2 = null;
public Form2()
{
InitializeComponent();
Broadcasting.setTextValue += new SetTextValue(setValue);
}
void setValue(object value)
{
label1.Text = value.ToString();
}
public static Form2 showfrom()
{
if (form2 == null)
{
form2 = new Form2();
}
return form2;
}
}
}
[解决办法]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form3 : Form
{
public static Form3 form3 = null;
public Form3()
{
InitializeComponent();
Broadcasting.setTextValue += new SetTextValue(setValue);
}
void setValue(object value)
{
label1.Text = value.ToString();
}
public static Form3 showform()
{
if (form3 == null)
{
form3 = new Form3();
}
return form3;
}
}
}
[解决办法]
先将form3的label1的modifier属性为public ,一个button1,
private void button1_Click(object sender, EventArgs e)
{
//显示form1
Form1 f1 = new Form1(this);
f1.Show();
f1.Hide();
}
private Form3 f3;
public Form1(Form3 parent)
{
InitializeComponent();
f3 = parent;
f3.label1.Text = textBox1.Text;
}
public static Form3 f1 = null;
public Form3()
{
InitializeComponent();
f1 = this;
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f2 = new Form1();
f2.Show();
f2.Hide();
}
public Form1()
{
InitializeComponent();
Form3.f1.label1.Text = textBox1.Text;
}