English 中文(简体)
装入程序后, 程序未完全隐藏在托盘中
原标题:After loading my application is not completly hide in tray

我有这样的代码:

public form()
{
    InitializeComponent();
    init(); //read ini and try to minimize
}

private void timer1_Tick(object sender, EventArgs e)
{
}

and in ini method I minimize form and hide it(in debug i can see form.visible = false), but when it leaves init method then it jumps on timer and change visible = true and i can see my app in taskbar and tray. I want see only tray icon. I use this to minimize form to tray.

到目前为止,我做了这个, 但也许被错误地应用了 因为当表单显示时 形式像清新, 它看起来怪怪的。

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

    private void minimizeWindow()//this method is called on form resize
    {
        if (FormWindowState.Minimized == this.WindowState)
        {
            notifyIcon1.Visible = true;
            this.Hide();
            this.ShowInTaskbar = false;
        }
        else if (FormWindowState.Normal == this.WindowState)
        {
            notifyIcon1.Visible = false;
            this.ShowInTaskbar = true;
        }
    }
最佳回答

简单解答:

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

    private void minimizeWindow()
    {
        if (FormWindowState.Minimized == this.WindowState)
        {
            notifyIcon1.Visible = true;
            this.Hide();
        }
        else if (FormWindowState.Normal == this.WindowState)
        {
            notifyIcon1.Visible = false;
        }
    }

        private void AAL_Load(object sender, EventArgs e)
    {
        minimizeWindow();//call it again
    }

不要使用表单。 showInTaskbar = 假的; 因为这样会有很多问题 。

问题回答

要隐藏窗口以隐藏任务栏, 您可以使用 showInTaskbar 属性。 在您的 init 方法中, 请尝试 :

form.ShowInTaskbar = false;

您可以在负载中添加最小化事件, 如果您的程序被设定为系统托盘最小化!

或者您可以在加载时添加 Me.Opaceity = 0 ( Me.Opaceity = 1 当再次点击 systeray 图标时), 然后隐藏任务栏按钮!





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签