Displaying you application on icon is one of the most
exciting part in the windows application. For this article i have used windows form and c#.Net.
Before moving forward
please check my some of the listbox articles Transfer
Listbox Items to Another Listbox Using C#.Net and VB.Net | How to Move List Box
Items to another List Box in C# in windows application.
Some other article are as follows: Email
Validation in Windows Application C#.Net and VB.Net | Validating Email ID in
TextBox in C# .Net, Displaying
More than One Month in the Windows Forms MonthCalendar Control Using C#.Net,
How
to get the selected date of a MonthCalendar control in C#, Open
For MDI Parent Using C#.Net and VB.Net.
So for this article first we will create a new windows
application and after that we will add blank form in it.
After creating a blank form we will add a notify control
from our toolbox.
Now we will set the icon from property window for NotifyIcon Control.
Now add the below code in your code form.
C#.Net
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace ProjectDemo_Windows
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
/// <summary>
/// For form load
/// </summary>
/// <param
name="sender"></param>
/// <param
name="e"></param>
private
void Form1_Load(object
sender, EventArgs e)
{
notifyIcon1.BalloonTipTitle = "Notify Icon";
notifyIcon1.BalloonTipText = "Notify Icon Test";
}
/// <summary>
/// For minimizing the window
/// </summary>
/// <param
name="sender"></param>
/// <param
name="e"></param>
private
void Form1_Resize(object
sender, EventArgs e)
{
if
(WindowState == FormWindowState.Minimized)
{
ShowInTaskbar = false;
notifyIcon1.Visible = true;
/*For
setting display interval of bubble tool tip*/
notifyIcon1.ShowBalloonTip(2000);
}
}
/// <summary>
/// for Rexize the window
/// </summary>
/// <param
name="sender"></param>
/// <param
name="e"></param>
private
void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs
e)
{
ShowInTaskbar = true;
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}
}
}
|
In above code first we are setting title and content for the
bubble tool tip which will appear after minimizing the form.
private
void Form1_Load(object
sender, EventArgs e)
{
notifyIcon1.BalloonTipTitle = "Notify Icon";
notifyIcon1.BalloonTipText = "Notify Icon Test";
}
|
Now will write code when user minimizes the form by using minimize button.
private void
Form1_Resize(object sender, EventArgs e)
{
if
(WindowState == FormWindowState.Minimized)
{
ShowInTaskbar = false;
notifyIcon1.Visible = true;
/*For
setting display interval of bubble tool tip*/
notifyIcon1.ShowBalloonTip(2000);
}
}
|
In above code we are checking what user is going to do if
form minimize event is getting fired then the above piece of code will execute.
Here is the final piece of code which is used for reopening the
for again when user click on icon.
private
void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs
e)
{
ShowInTaskbar = true;
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}
|
Now we have done. Now run the application.
Now click on minimize button. You will see your form in
system tray
Now double click on system tray icon to re-open the form.
DOWNLOAD
0 comments:
Please let me know your view