有两个窗体A,BA中有1个TextBox , 1个Button
代码
public delegate void MyDelete(string text);
public event MyDelete MyEvent; private void button1_Click(object sender, EventArgs e)
{
string text = this.textBox1.Text.ToString();
MyEvent(text);
}B中只有1个TextBox
我想让A中每次点击Button,B中的TextBox中的值自动变成A中TextBox中的值
public void fun(string text)
{
this.textBox1.Text=text;
}请问B中德的代码应该怎么写
代码
public delegate void MyDelete(string text);
public event MyDelete MyEvent; private void button1_Click(object sender, EventArgs e)
{
string text = this.textBox1.Text.ToString();
MyEvent(text);
}B中只有1个TextBox
我想让A中每次点击Button,B中的TextBox中的值自动变成A中TextBox中的值
public void fun(string text)
{
this.textBox1.Text=text;
}请问B中德的代码应该怎么写
child1.MyEvent += new Child1.MyDelete(fun);可是不能实现,,,请问具体应该怎么写
child1.MyEvent += new Child1.MyDelete(fun);
应该放在那里
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public delegate void SendString(string str);
public partial class MainWindow : Window
{
public static SendString sendString;
public MainWindow()
{
InitializeComponent();
this.button1.Click +=new RoutedEventHandler(button1_Click);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
if (this.textBox1.Text != null)
{
Window2 win2 = new Window2();
sendString(this.textBox1.Text);
win2.Show();
}
}
}
}
namespace EventTest
{
/// <summary>
/// Window2.xaml 的交互逻辑
/// </summary>
public partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
MainWindow.sendString =new SendString(this.ReceiveString);
}
private void ReceiveString(string str)
{
this.textBox1.Text = str;
}
}
}这个对不对(WPF)
Form2 f = new Form2();
private void button1_Click(object sender, EventArgs e)
{
f.Show();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = Form2.TxtBox_vaule;
}From2的代码 from中只有一个TextBox
private static string txtBox_vaule; public static string TxtBox_vaule
{
get { return Form2.txtBox_vaule; }
set { Form2.txtBox_vaule = value; }
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
txtBox_vaule = textBox1.Text;
}
在A中定义一个B窗体类型的对象 b,
将你的B窗体传递给A的对象b,
A中间点击按钮直接更改b中的textbox的值就行,需要将texbox的类型该为public
如果是希望A修改,B也修改,那就在A的valuechanged事件中修改B的值。一个这么简单的事情,搞出一堆破东西出来。