简体   繁体   English

C#Windows应用程序无法正确显示在系统托盘中

[英]C# Windows Application Doesnt Show In System Tray Correctly

i am trying to get ac# winforms application to startup only in the system tray but when i use the following commands it shows in the system tray but also shows as a little title bar just above the taskbar on the left hand side above the start button (windows xp) 我试图让ac#winforms应用程序仅在系统托盘中启动,但是当我使用以下命令时,它在系统托盘中显示,但在开始按钮上方左侧的任务栏上方也显示为小标题栏(Windows XP)

The funny thing is that it only happens when i run the application outside of visual studio. 有趣的是,只有当我在Visual Studio外部运行应用程序时,它才会发生。

Does anyone know what im doing wrong? 有人知道我在做什么错吗?

Constructor or Form_Load.... 构造函数或Form_Load。

this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
this.Hide();

Add an event handler for the form's Resize event that will hide the application when it's minimized. 为表单的Resize事件添加一个事件处理程序,该事件处理程序在最小化时将隐藏应用程序。 That way, it won't appear on the task bar. 这样,它就不会出现在任务栏上。

private void Form1_Resize(object sender, System.EventArgs e)
{
   if (FormWindowState.Minimized == WindowState)
      Hide();
}

Try this 尝试这个

this.Resize +=new EventHandler(Form1_Resize);
private void Form1_Resize(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        this.Hide();
    }
}
private void ntfIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button==MouseButtons.Left)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.Show();
                    this.WindowState = FormWindowState.Normal;
                }
                else
                {
                    this.WindowState = FormWindowState.Minimized;
                    this.Hide();
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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