有两个窗体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中德的代码应该怎么写

解决方案 »

  1.   

    本帖最后由 bdmh 于 2011-07-18 16:26:54 编辑
      

  2.   

    我写了                Child1 child1 = new Child1();
                    child1.MyEvent += new Child1.MyDelete(fun);可是不能实现,,,请问具体应该怎么写
      

  3.   

     Child1 child1 = new Child1();
      child1.MyEvent += new Child1.MyDelete(fun);
    应该放在那里
      

  4.   

    用session就行啊 ,把textbox1的值放到session中 b页面在取
      

  5.   

    B中注册事件,响应A的Textbox1的TextChanged事件,进行同步。
      

  6.   

    提示“MyEvent(text);”未将对象引用到实例啊
      

  7.   

    提示“MyEvent(text);”未将对象引用到实例啊
      

  8.   

    namespace EventTest
    {
        /// <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)
      

  9.   

    Form1的代码:有两个button一个textbox  
    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;
            }
      

  10.   

    直接用控件关联也能实现:
    在A中定义一个B窗体类型的对象 b,
    将你的B窗体传递给A的对象b,
    A中间点击按钮直接更改b中的textbox的值就行,需要将texbox的类型该为public
      

  11.   

    在需要修改值的方法中,找到需要修改的两个控件对象,同时就改就完了。
    如果是希望A修改,B也修改,那就在A的valuechanged事件中修改B的值。一个这么简单的事情,搞出一堆破东西出来。