我认为您希望在活动中同时更新两种表格OnLoad
。
这是第二种形式的代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Application.DoEvents();
}
public void SetProgress(int value)
{
progressBar1.Value=value;
}
public void SetProgress(int value, int max)
{
progressBar1.Maximum=max;
progressBar1.Value=value;
}
public void Increment()
{
progressBar1.PerformStep();
}
}
这是主要形式的代码:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.Show();
label1.Text="Initializing Form1";
Form1 dlg=new Form1();
dlg.Show();
Application.DoEvents();
dlg.Location=new Point(this.Location.X+this.Size.Width+5, this.Location.Y);
System.Threading.Thread.Sleep(1400);
for(int i=0; i<10; i++)
{
label1.Text="Setting Progress Bar at "+(i+1).ToString()+" of 10";
dlg.SetProgress(i+1, 10);
Application.DoEvents();
System.Threading.Thread.Sleep(1400);
}
label1.Text="Done!";
}
}
这一切都始于
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}