状况:我在做两个窗体的传值问题,主窗体form1,子窗体form2,在form1放一个label1来显示从form2传回来的值
问题是:当我从form2传值到form1时,值是可以取到的,但是需要用鼠标去点按钮或中keyDown事件才可以触发显示值到label1上。
我的需求是:我想只要切换到form1主窗体就会马上触发显示label2上的值?
这样怎样做到?能帮我解决问题的给高分,我现在比较急。第一次用的C/S模式做程序。
问题是:当我从form2传值到form1时,值是可以取到的,但是需要用鼠标去点按钮或中keyDown事件才可以触发显示值到label1上。
我的需求是:我想只要切换到form1主窗体就会马上触发显示label2上的值?
这样怎样做到?能帮我解决问题的给高分,我现在比较急。第一次用的C/S模式做程序。
窗体只需要一个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的值。
你的意思是需要关闭form2后显示还是不关闭form2切换到后就显示呢?
我的意思是要点击一个button按钮关闭form2,切换到form1主窗体form2上的值就会马上显示到form1的label上,就这个意思。
{
this.label1.Text = "你的全局变量";
}
我是想只要切换到form1就马上可以显示,呵呵~明白我的意思了吗?朋友