private void Form2_Load(object sender, System.EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 5000;

}
private void timer1_Tick(object sender, System.EventArgs e)
{
Form1 newform1 = new Form1();
                           newform1.label1.text = "abc";
}
但是当我打开form1中时,label1的值没有变化呢,这是为什么呢,我设了断点之后,进行跟踪,newform1.label1.text的值确实是abc,为什么在form1窗体中label1的值就不是abc呢.

解决方案 »

  1.   

    看看这个,
    http://community.csdn.net/Expert/topic/4579/4579224.xml?temp=.1629297
      

  2.   

    public delegate void TimerHandler();
    public event TimerHandler time;
    private void Form1_Load(object sender, System.EventArgs e)
    {
    Form2 f2 = new Form2();
    f2.Show();
    time += new TimerHandler(f2.Fill);
    time();
    }public void Fill()
    {
    label1.Text = "abc";

    }
      

  3.   

    fill方法应该在form1中呢,那么form2怎么能调用fill呢.
      

  4.   

    private void Form2_Load(object sender, System.EventArgs e)
    {
    timer1.Enabled = true;
    timer1.Interval = 5000;}
    private void timer1_Tick(object sender, System.EventArgs e)
    {
    Form1 newform1 = new Form1();
     newform1.label1.text = "abc";
    newform1.show();
    }
    -----------------------------------------------声明label1设为public,在 newform1.label1.text = "abc";后加newform1.show();,测试过了可以。
    如果你不是在赋值后show()而是在其他地方新开一个form1,那是Form1的另一个新实例,当然不会label1的值是abc了
      

  5.   

    Form1 :
     public label1
     Form2 newform2 = new Form2();
     newform2.Parent=this;
     
    Form2 :
     
      

  6.   

    public  Form1 parent;
    this.parent.组件操作;
    上面的
     newform2.Parent=this;
    错了,应该小写
      

  7.   

    Timer属于Thread的一类
    在Thread中直接操作组件时
    主线程并不更新该组件显示状态也就是Timer_Tick事件中直接操作label控件
    Application并不通知form去刷新label控件这是解决的方法一般有两种
    一是用委托的方法操作label控件二是直接操作label控件,再通知form去刷新label控件====CSDN 小助手 V2.5 2005年11月05日发布====
    CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
    界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
    下载:http://szlawbook.com/csdnv2