C# close to tray (like msn messenger)

≯℡__Kan透↙ 提交于 2019-12-05 10:01:41

try this:

bool _closingFromMenu;

void NOTIFYICON_EXIT_MENU_HANDLER(object sender, EventArgs e)
{
    _closingFromMenu = true;
    Close();
}

//form closing handler
FormClosing +=(a,b) =>{
    if(_closingFromMenu){
        Close();
    }
    else{
        e.Cancel = true;
        //do minimize stuff;
    }
}

or if you have only one form you can call Application.Exit(); in context menu item handler

You probably want to track the state of the application based on the actions of the user as that's not necessarily reflected in the state of the window. So when the user selects Exit from the menu you need to set a flag to indicate that you're really exiting, not just hiding the window.

Just make your Context Menu close event call Application.Exit()

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!