gpt4 book ai didi

C# trayicon 使用 wpf

转载 作者:可可西里 更新时间:2023-11-01 08:32:53 28 4
gpt4 key购买 nike

虽然我在 unity3D 中编写 C# 脚本已经有几年了,但我对 C# 编程还很陌生。我目前正在尝试制作一个 WPF 托盘图标,我在网上找到的所有资源都告诉我使用

System.Windows.Forms

但是 .Forms 在 System.Windows 中对我来说不可用,我不知道为什么不可用。谁能帮我解决这个问题?

最佳答案

您需要添加对 System.Window.Forms 和 System.Drawing 程序集的引用,然后像这样使用它。假设您尝试将 Window 最小化到托盘图标并在用户单击该图标时再次显示它:

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);
}
}

关于C# trayicon 使用 wpf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12428006/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com