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呢.
{
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呢.
解决方案 »
- 自动按键
- datagirdview 单元格问题 急!
- MessageBox.Show()报错,容量超出了最大容量。参数名: capacity
- WEBCLIENT,POST,参数,乱码
- 控制台程序不能生成,提示说一个.tmp文件不是有效的资源文件,大家帮帮我啊。
- 未将对象引用设置到对象的实例(高手过目,急待解决)
- 关于定义全局变量的问题。。。
- 大家好!请问什么时候用到结构体?谢谢!
- 【分享】StackOverflow监控系统Opserver开源
- 如何在c#中把11aa22bb这样一个字符串转成byte[]{0x11,0xaa,0x22,0xbb}
- 自定义界面风格问题
- 怎样在winfrom中创建存储过程?
http://community.csdn.net/Expert/topic/4579/4579224.xml?temp=.1629297
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";
}
{
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了
public label1
Form2 newform2 = new Form2();
newform2.Parent=this;
Form2 :
this.parent.组件操作;
上面的
newform2.Parent=this;
错了,应该小写
在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