A Simple Windows Forms Application - Using With Loader

In this article, we will learn how the Loader works in between two Forms of a simple Windows Application.

Loader

Loader is an operating system that is used for loading Programs and Libraries. It is one of the essential stages in the process of starting a program.

Step 1

Click New >> Project >> Visual C# >> Windows >> Windows Forms Application. Enter your Project name and click OK.

Step 2

Click the View->Select Toolbox. We are using this Toolbox to design the Form in Windows application.

Windows Application 

Step 3

In Toolbox, we have to add Picture Box and click the Picture Box tasks to choose the image.


 

Step 4

Click the Local Resources to import the Loader.gif file and click OK.


 

Step 5

Click the Size Mode Tab and change to CenterImage.


 

Step 6

Click the Properties menu of Picture Box. Toggle Visible option as False.


 

Step 7

Click the Toolbox and Add >> Background Worker.


 

Step 8

Click the Background Worker properties and add the backgroundWorker1_DoWork, backgroundWorker1_RunWorker to be completed for the event to make the function more accurate.

Where,

Header File

  1. using System.Threading;  

C# CODE 

  1. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {  
  2.     if (LoginUserNameTB.Text == "admin" && LoginPasswordTB.Text == "admin") {  
  3.         Thread.Sleep(1000);  
  4.         isloginSuccess = true;  
  5.     } else {  
  6.         isloginSuccess = false;  
  7.     }  
  8. }  
  9. private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {  
  10.     if (isloginSuccess) {  
  11.         MessageBox.Show("Login Succesfuly");  
  12.         this.Close();  
  13.     } else {  
  14.         MessageBox.Show("Check uname & Password");  
  15.         pcloader.Visible = false;  
  16.     }  
  17. }  
  18. Step 9  
  19. Click the BUTTON Properties to add the  
  20. function  
  21. for button1_Click.  
  22. public bool isloginSuccess = false;  
  23. private void button1_Click(object sender, EventArgs e) {  
  24.     pcloader.Visible = true;  
  25.     pcloader.Dock = DockStyle.Fill;  
  26.     backgroundWorker1.RunWorkerAsync();  
  27. }   

Step 10

Add new form and save it.



Click View->Select Toolbox. We are using the Toolbox to design the Form in Window Application.


 

Step 11

Click the Register(Form2) Properties and add the Register_Load function.

C# CODE 

  1. Form1 Objlogin;  
  2. private void Register_Load(object sender, EventArgs e) {  
  3.     Objlogin = new Form1();  
  4.     Objlogin.ShowDialog();  
  5.     if (Objlogin.isloginSuccess == true) {} else {  
  6.         this.Close();  
  7.     }  
  8. }   

Step 12

Press F5 or "Build and Run" the application to get the Loader running.

Result Loader is running.


Up Next
    Ebook Download
    View all
    Learn
    View all