简体   繁体   中英

How to minimize an application to system tray?

How to minimize an application to system tray?

My application is developed in C#.Net. I have written code such that the Form minimizes to system tray if a button is clicked after selecting some settings from comboboxes. The button gets disabled after clicking once. So, I can't use that button to minimize the Form again. The Form pops up when a RichTextBox is populated with data received from COM port. Everything is working fine.

The problem is when the minimized Form pops up after it receives serial data I need an option to minimize it back to system tray again so that it can pop up again when new data is populated in the RichTextBox.

I don't want to add another button to do this whenever Form pops up. Is there any other way to do it?

It would be better if somebody provides code so that the app minimizes to system tray if minimize button in the title bar is clicked.

I just want to know the function name I have to use, something like private Form1_Resize() . Actually, Resize event can't be used because it triggers whenever form is minimized or maximized. I need it to trigger only when Form minimized.

There are thousand of HowTo's out there, did you try Google? Just one example: http://alperguc.blogspot.de/2008/11/c-system-tray-minimize-to-tray-with.html

How about adding a key to minimize the form?

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Escape)
    {
        this.WindowState = FormWindowState.Minimized;
    }
}
private void frmMain_Resize(object sender, EventArgs e)
{
 if (FormWindowState.Minimized == this.WindowState)
{
 mynotifyicon.Visible = true;
 mynotifyicon.ShowBalloonTip(500);
 this.Hide();
}
 else if (FormWindowState.Normal == this.WindowState)
 {
 mynotifyicon.Visible = false;
 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM