111,092
社区成员




使用MDI窗体, 控制打开N个form. form并排排列, 每个form中放少量控件
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void button1_Click(object sender, EventArgs e)
{
button1.Text = "测试开始";
Test();
}
void Test()
{
Thread.Sleep(10000);
this.button1.Text = "测试完成";
}
}
}
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
async void button1_Click(object sender, EventArgs e)
{
button1.Text = "测试开始";
await Test();
this.button1.Text = "测试完成";
}
Task Test()
{
return Task.Run(() => //把与UI刷新无关的语句放到这个匿名委托中执行
{
Thread.Sleep(10000);
});
}
}
}
你会发现在耗时过程执行过程中也能自由地拖动窗口。using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
async void button1_Click(object sender, EventArgs e)
{
button1.Text = "测试开始";
await Test();
this.button1.Text = "测试完成";
}
Task Test()
{
return Task.Run(() => //把与UI刷新无关的语句放到这个匿名委托中执行
{
Thread.Sleep(2500);
this.button1.BeginInvoke((Action)delegate
{
this.button1.Text = "1";
});
Thread.Sleep(2500);
this.button1.BeginInvoke((Action)delegate
{
this.button1.Text = "2";
});
Thread.Sleep(2500);
this.button1.BeginInvoke((Action)delegate
{
this.button1.Text = "3";
});
Thread.Sleep(2500);
});
}
}
}