状况:我在做两个窗体的传值问题,主窗体form1,子窗体form2,在form1放一个label1来显示从form2传回来的值
问题是:当我从form2传值到form1时,值是可以取到的,但是需要用鼠标去点按钮或中keyDown事件才可以触发显示值到label1上。
我的需求是:我想只要切换到form1主窗体就会马上触发显示label2上的值?
这样怎样做到?能帮我解决问题的给高分,我现在比较急。第一次用的C/S模式做程序。

解决方案 »

  1.   

    晕:如果让form2更改的时候,就在form1的label上显示。这个你要吗?
      

  2.   

    以下是form1的后台代码,
    窗体只需要一个button和一个lableusing System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 obj = new Form2(this.label1);
                obj.Show();
            }
        }
    }以下是form2的cs代码
    窗体加入一个textbox就行using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication3
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        Label form2lb;        public Form2(Label lb)
            {
                InitializeComponent();
                form2lb = lb;
            }        private void Form2_Load(object sender, EventArgs e)
            {        }        private void textBox1_TextChanged(object sender, EventArgs e)
            {
                form2lb.Text = this.textBox1.Text;
            }
        }
    }
    打开form2后,在文本框里输入值 ,即时改变form1窗体lable的值。
      

  3.   

    http://hi.baidu.com/libinguest/blog/item/0110fb1f077de96af624e4b0.html
      

  4.   

    不是我要的结果,我是说在form1中已经有存在的全局变量,我要这个form1只要获得焦点就会给它上面的label1赋值,传值我能成功了
      

  5.   


    你的意思是需要关闭form2后显示还是不关闭form2切换到后就显示呢?
      

  6.   

    你的意思是需要关闭form2后显示还是不关闭form2切换到form1就显示呢?
      

  7.   


    我的意思是要点击一个button按钮关闭form2,切换到form1主窗体form2上的值就会马上显示到form1的label上,就这个意思。
      

  8.   

            private void Form1_Activated(object sender, EventArgs e)
            {
                this.label1.Text = "你的全局变量";
            }
      

  9.   

    我头都晕了,你写程序可真有精神,I服了YOU
      

  10.   

    form2的作用是设置一些参数,设置完后我需要传一些东西到form1显示,就是这个意思,问题是我传回来了,在form1中的变量有值了,可是却需要一个按钮或键盘按下事件触发才能显示,这样不好。
    我是想只要切换到form1就马上可以显示,呵呵~明白我的意思了吗?朋友
      

  11.   

    Activated多了解一些window的事件,就会知道的