最简单的办法有一个程序中使用.NET 4自行最小化到系统托盘 [英] Easiest way to have a program minimize itself to the system tray using .NET 4

查看:126
本文介绍了最简单的办法有一个程序中使用.NET 4自行最小化到系统托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个新的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?

推荐答案

<一个href="http://social.msdn.microsoft.com/Forums/ar/wpf/thread/21992d0b-a02c-4042-a188-47b0a2b99b0b">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);
    }
}

这篇关于最简单的办法有一个程序中使用.NET 4自行最小化到系统托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆