我有这个代码:
namespace TuyenTk
{
public partial class Form1 : Form
{
Form2 _form2 = new Form2("");
public Form1()
{
InitializeComponent();
_form2.Show();
int i = 0;
while (i < 5)
{
_form2.label1.Text = "" + i;
Thread.Sleep(500);
i++;
}
}
}
public class Form2 : Form
{
public System.Windows.Forms.Label label1;
public System.ComponentModel.Container components = null;
public Form2()
{
InitializeComponent();
}
private void InitializeComponent(string t)
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(5, 5);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(290, 100);
this.label1.TabIndex = 0;
this.label1.Text = t;
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(300, 100);
this.ControlBox = false;
this.Controls.Add(this.label1);
this.Name = "Form2";
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.ShowInTaskbar = false;
this.ResumeLayout(false);
}
}
}
当 Form1 运行时,它显示 Form2,但 Form2.label1 背景是白色的,并且没有文字。
2.5 秒后,Form2.label1.Text = 4。所以 i 的值 0、1、2、3 不会出现。我该如何解决?非常感谢你。