Windows Forms: Metro Wait Form in C#
By FoxLearn 5/26/2017 9:00:38 PM 4.82K
Create Metro WaitForm Dialog in C# using Metro Framework, Modern UI
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
- Windows Forms: Metro TextBox in C#
- Windows Forms: Metro GridView in C#
- Windows Forms: Metro ListView in C#
- Windows Forms: How to use Modern UI Metro Framework in C#
- Windows Forms: Download and Install Metro Framework
- Windows Forms: Metro Message Box in C#
- Windows Forms: Modern UI Login Form in C#
- Windows Forms: How to use WinForms Modern UI Metro Framework in C#
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024
How to use Factory Method Pattern in C#
02/16/2024