Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "MetroWaitForm" and then click OK
Step 2: Right click on your project select Manage NuGet Packages -> Search metro framework -> Install
Step 3: Design your metro form as below
Name your main form: frmMain

Name your wait form: frmWaitForm

Step 4: Add code to handle frmWaitForm
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WaitFormDemo
{
public partial class frmWaitForm : Form
{
public Action Worker { get; set; }
public frmWaitForm(Action worker)
{
InitializeComponent();
if (worker == null)
throw new ArgumentNullException();
Worker = worker;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//Start new thread for waitform
Task.Factory.StartNew(Worker).ContinueWith(t => { this.Close(); }, TaskScheduler.FromCurrentSynchronizationContext());
}
}
}
Add code to handle frmMain
using System;
using System.Threading;
namespace MetroWaitForm
{
public partial class frmMain : MetroFramework.Forms.MetroForm
{
public frmMain()
{
InitializeComponent();
}
void Save()
{
//Only for demo
for (int i = 0; i <= 100; i++)
{
Thread.Sleep(20);
//Save data
}
}
private void btnSave_Click(object sender, EventArgs e)
{
//Open waitform dialog
using (var waitForm = new frmWaitForm(Save))
{
waitForm.ShowDialog(this);
}
}
}
}
VIDEO TUTORIALS