要实现加载中效果,可以使用以下方法:
private void btnLoad_Click(object sender, EventArgs e)
{
progressBar1.Visible = true;
// 加载数据
// ...
progressBar1.Visible = false;
}
private void btnLoad_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
// 加载数据
// ...
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// 加载完成后的操作
// ...
}
private async void btnLoad_Click(object sender, EventArgs e)
{
lblLoading.Visible = true;
// 加载数据
await LoadDataAsync();
lblLoading.Visible = false;
}
private async Task LoadDataAsync()
{
await Task.Run(() =>
{
// 加载数据
// ...
});
}
以上是几种常见的实现加载中效果的方法,可以根据具体情况选择适合的方式。