[英]c# label on form not reflecting text change
OK, I am trying to help someone with a C# winform app for a dice roller.好的,我正在尝试帮助某人使用 C# winform 应用程序进行掷骰子。 The code below is what they have done to get a basic test structure working - I suspect they don't have much experience with classes yet.下面的代码是他们为使基本测试结构正常工作所做的工作 - 我怀疑他们对类还没有太多经验。 Anyway the problem is that the text change for label1 is never updated on the form and I don't understand why.无论如何,问题是 label1 的文本更改永远不会在表单上更新,我不明白为什么。 Any suggestions?有什么建议?
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Dice_Roller
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void DiceOne()
{
label1.Text = "test";
}
public void Form1_Load(object sender, EventArgs e)
{
Form1 doIt = new Form1();
doIt.DiceOne();
label1.Refresh();
}
}
}
Just use like this, it should work.像这样使用,它应该可以工作。
private void Form1_Load(object sender, EventArgs e)
{
//Form1 doIt = new Form1();
DiceOne(); //change here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.