This article will show you how you can display the please
wait or loading message on button click in windows application using C#.net.
This will help to display loading message while interacting with DB.
Some of my previous articles are as follows: Save
Panel with Control Inside It as Image C#.net, VB.net in windows application,
Dynamically
Change Form Background Color C#.Net in Windows Application, Dynamically
Add Textbox Control in Panel and Clear All on Single Click Using C#.Net in
Windows Application, Confirmation
Message on Button Click and Capture YES/NO Click by User in Windows
application, C#.
So for this article first we will create a new windows
application and add two form one form for please wait message or for loading
message.
Now add one more form with button.
Now add the below code on button click event of the form.
C#.Net Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void button2_Click(object
sender, EventArgs e)
{
PleaseWait
objPleaseWait = new PleaseWait();
objPleaseWait.Show();
Application.DoEvents();
/*Remove
the function and
put your
function which will interact with DB */
DBOperation();
objPleaseWait.Close();
}
public
void DBOperation()
{
for
(int i = 0; i < 2; i++)
{
System.Threading.Thread.Sleep(1000);
}
}
}
}
|
VB.Net Code
Imports System.Drawing
Imports System.Windows.Forms
Namespace WindowsFormsApplication1
Partial Public Class Form1
Inherits
Form
Public
Sub New()
InitializeComponent()
End Sub
Private
Sub button2_Click(ByVal
sender As Object,
ByVal e As
EventArgs)
Dim
objPleaseWait As New
PleaseWait()
objPleaseWait.Show()
Application.DoEvents()
'Remove
the function and
' put your function which will interact
with DB
DBOperation()
objPleaseWait.Close()
End Sub
Public
Sub DBOperation()
For
i As Integer
= 0 To 1
System.Threading.Thread.Sleep(1000)
Next
End Sub
End Class
End Namespace
|
In above code simply I have open the please wait form and
then application.doevents for processing the data. After completing the process
just close the form.
Now run the application and check the output.
Thanks A lot buddy Its really work for me
ReplyDelete