要實現加載中效果,可以使用以下方法:
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(() =>
{
// 加載數據
// ...
});
}
以上是幾種常見的實現加載中效果的方法,可以根據具體情況選擇適合的方式。