How to create process Loader in Window Application
1.
Create ModelLodingUI Window Form and set the property : FromBoderStyle-
None
2.
Drag & Drop Picture Box and set Loading
Image.
3.
Paste following code:
4.
namespace LoadingProcess
5.
{
6. public partial class ModalLoadingUI : Form
7.
{
8.
#region Constants
9.
public bool CloseMe =
false;
10. #endregion
11.
12. public
ModalLoadingUI()
13. {
14. InitializeComponent();
15. }
16. private
void ModalLoadingUI_Load(object sender, EventArgs
e)
17. {
18.
19. }
20. public void LoadForm()
21. {
22. this.Opacity
= 0.5;
23. this.BackColor
= Color.Gray;
24. this.Show();
25. while
(true)
26. {
27. if
(CloseMe)
28. {
29. Application.DoEvents();
30. CloseMe = false;
31.
32. this.Close();
33. break;
34. }
35. else
36. {
37. Application.DoEvents();
38. }
39. }
40.
41. }
42.
43. }
44.
}
II. Create Static Class like Program.cs:
static class Program
{
static ModalLoadingUI FormLoader;
public static void
StartLoder()
{
FormLoader = new ModalLoadingUI();
ThreadStart
TS = new ThreadStart(FormLoader.LoadForm);
Thread
T = new Thread(TS);
T.Start();
Thread.Sleep(5000);
}
public static void
StoptLoder()
{
FormLoader.CloseMe = true;
}
}
III. Call the function on page where you want
to show the process.
private void button1_Click(object
sender, EventArgs e)
{
Program.StartLoder();
//
-----rite you code like saveData()-------------
Thread.Sleep(5000);
//-------------------
Program.StoptLoder(); }
Comments
Post a Comment