Saturday, October 16, 2010

C# Tutorial: NotifyIcon with ContextMenuStrip [Tray Balloon]

Here is the code

private void Form1_SizeChanged(object sender, EventArgs e)
{
    // Check if the Form is minimized
    if (this.WindowState == FormWindowState.Minimized)
    {
        // If the notifyIcon1 doesn't have a Icon then it won't show up!
        notifyIcon1.Icon = SystemIcons.Application;
        notifyIcon1.BalloonTipText = "Your Form has minimized to tray";
        notifyIcon1.ShowBalloonTip(1000); 
    }
    // Check if the Form it's in Normal State
    else if (this.WindowState == FormWindowState.Normal)
    {
        notifyIcon1.BalloonTipText = "Your Form has come back to Normal";
        notifyIcon1.ShowBalloonTip(1000); 
    }
}

private void showFormToolStripMenuItem_Click(object sender, EventArgs e)
{
    this.WindowState = FormWindowState.Normal;
}

private void blablaToolStripMenuItem_Click(object sender, EventArgs e)
{
    MessageBox.Show("SUBSCRIBE :)");
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
    Application.Exit();
}

private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
    this.WindowState = FormWindowState.Normal;
}

Or download the solution

1 comment: