最简单的办法有一个程序中使用.NET 4自行最小化到系统托盘最小化、最简单、有一个、系统托盘

2023-09-08 09:03:42 作者:屿风

我正在做一个新的WPF应用程序,我需要能够最大限度地减少应用程序,并有很好的舒适和在系统托盘中,旁边的时钟(或在一般地区)。

I'm making a new WPF application and I need to be able to minimize the application and have nice and snug in the system tray, right beside the clock (or in that general area).

这有工作在Windows XP,Vista和7。我没有支持老版本的Windows。

This has to work on Windows XP, Vista and 7. I don't have to support older versions of Windows.

什么是,如果我使用.NET 4中实现这一目标的最简单的方法是什么?

What's the simplest way to achieve this if I'm using .NET 4?

推荐答案

Example在MSDN论坛

下面是一个简单的例子来说明如何最大限度地减少到通知区域。您需要将引用添加到System.Window.Forms和System.Drawing中装配。

Here's a quick example to show how to minimise to the notification area. You need to add references to the System.Window.Forms and System.Drawing assemblies.

public partial class Window1 : System.Windows.Window
{

    public Window1()
    {
        InitializeComponent();

        System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
        ni.Icon = new System.Drawing.Icon("Main.ico");
        ni.Visible = true;
        ni.DoubleClick += 
            delegate(object sender, EventArgs args)
            {
                this.Show();
                this.WindowState = WindowState.Normal;
            };
    }

    protected override void OnStateChanged(EventArgs e)
    {
        if (WindowState == System.Windows.WindowState.Minimized)
            this.Hide();

        base.OnStateChanged(e);
    }
}
 
精彩推荐
图片推荐