使用WPF C#托盘图标 [英] C# trayicon using wpf

查看:380
本文介绍了使用WPF C#托盘图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的编程C#,虽然我照本宣科C#中unity3D了几年。
目前,我正在试图让一个WPF托盘图标,所有我在网上找到的消息来源告诉我用

I'm very new to programming C#, though I've scripted C# in unity3D for a few years. I'm currently trying to make a WPF tray icon, all the sources I've found on the net tell me to use

System.Windows.Forms

不过者,恕不暂时不提供System.Windows我,我不知道为什么。谁能帮我这个?

However .Forms is not available in System.Windows for me, and I have no idea why not. Can anyone help me with this?

推荐答案

您需要添加到System.Window.Forms和引用System.Drawing中装配和然后使用它像这样。假如你试图将窗口最小化到托盘图标,再次显示当用户点击该图标:

You need to add references to the System.Window.Forms and System.Drawing assemblies and then you use it like this. Suppose you try to minimize the Window to tray icon and show it again when user click that icon:

public partial class Window : System.Windows.Window
{

    public Window()
    {
        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 == WindowState.Minimized)
            this.Hide();

        base.OnStateChanged(e);
    }
}

这篇关于使用WPF C#托盘图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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