110,533
社区成员
发帖
与我相关
我的任务
分享
Form1 fm = new Form1();
fm.label1.Text = "sad哈撒给大会上将打火机撒谎";
Application.Run(fm);
fm.label1.Text = "ashdaskdhajsdhkjashdjsa";// 这个数据不显示
fm.label1.Refresh();
public void change(string text)
{ this.label1.Text = text; }
在Main中调用 Form1 fm = new Form1();
fm.change("赛思结合");
Application.Run(fm);
fm.change("ashdaskdhajsdhkjashdjsa");//这个没变动
这和我一楼发的结果是一样的都是Application.Run之后就变动不了数值了 应该怎么做?[/quote]
创建的窗体Application.Run之后,你确定你理解这句话?初学者是还没有能理解Application.Run这句话的意思的。
你要明白你写的程序是事件驱动,你要做的是在不同事件里写代码,而不是控制具体什么时候做什么。比如你要在创建窗体以后改标签文字,那么在窗体的Form1_Load事件可以写代码,如果你要在创建窗体以后10秒钟修改标签文字,那么在窗体里加个定时器组件,定时10秒产生的事件里写,当然也可以按了键盘这个事件,按了鼠标这个事件等等等。。。 public void change(string text)
{ this.label1.Text = text; }
Form1 fm = new Form1();
fm.change("赛思结合");
Application.Run(fm);
fm.change("ashdaskdhajsdhkjashdjsa");//这个没变动
这和我一楼发的结果是一样的都是Application.Run之后就变动不了数值了 应该怎么做?[/quote] public void change(string text)
{ this.label1.Text = text; }
Form1 fm = new Form1();
fm.change("赛思结合");
Application.Run(fm);
fm.change("ashdaskdhajsdhkjashdjsa");//这个没变动
这和我一楼发的结果是一样的都是Application.Run之后就变动不了数值了 应该怎么做?[/quote][quote=引用 5 楼 cooclk2019 的回复:]
[quote=引用 2 楼 hztltgg 的回复:]
Application.Run 后就进入消息循环了,下面的代码没执行到当然不会显示了。
public void change(string text)
{ this.label1.Text = text; }
Form1 fm = new Form1();
fm.change("赛思结合");
Application.Run(fm);
fm.change("ashdaskdhajsdhkjashdjsa");//这个没变动
这和我一楼发的结果是一样的都是Application.Run之后就变动不了数值了 应该怎么做?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.label1.Text = "123456";
}
}
[quote=引用 2 楼 hztltgg 的回复:]
Application.Run 后就进入消息循环了,下面的代码没执行到当然不会显示了。
[quote=引用 2 楼 hztltgg 的回复:] Application.Run 后就进入消息循环了,下面的代码没执行到当然不会显示了。
Application.Run 后就进入消息循环了,下面的代码没执行到当然不会显示了。
你这个代码写在哪里,写在main方法里面吗?