WPF控件--NotifyIcon
来源:互联网 发布:查看linux 网卡 编辑:程序博客网 时间:2024/05/21 06:17
1.在什么地方找到NotifyIcon
普通的WPF控件基本上都是在该命名空间下:System.Windows.Controls,该命名空间在C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll下。也就是说是.net framework3.0之后才支持的。
那难道在WPF下就不能使用NotifyIcon了吗?
在MSDN上有以下关于通知图标的示例:http://msdn.microsoft.com/zh-cn/library/aa972170(VS.90).aspx
using System;using System.Windows;using System.Windows.Forms; // NotifyIcon controlusing System.Drawing; // Iconpublic partial class MainWindow : Window{ NotifyIcon notifyIcon; public MainWindow() { InitializeComponent(); } void click(object sender, RoutedEventArgs e) { // Configure and show a notification icon in the system tray this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "Hello, NotifyIcon!"; this.notifyIcon.Text = "Hello, NotifyIcon!"; this.notifyIcon.Icon = new System.Drawing.Icon("NotifyIcon.ico"); this.notifyIcon.Visible = true; this.notifyIcon.ShowBalloonTip(1000); }}
其中包含NotifyIcon控件,请注意它的命名空间:System.Windows.Forms; ,该命名空间是在C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll下。所以说此处使用的NotifyIcon控件其实是.net framework 2.0就提供的在winform下面是用的控件。
2.怎么使用NotifyIcon
App.xaml
<Application x:Class="NotifyIconStd.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ShutdownMode="OnExplicitShutdown" Startup="ApplicationStartup" Exit="ApplicationExit"> <Application.Resources> </Application.Resources></Application>
App.xaml.cs
using System;using System.Collections.Generic;using System.Configuration;using System.Data;using System.Linq;using System.Windows;using System.Windows.Forms;using Application = System.Windows.Application;namespace NotifyIconStd{ public partial class App : Application { private static NotifyIcon trayIcon; private void ApplicationStartup(object sender, StartupEventArgs e) { RemoveTrayIcon(); AddTrayIcon(); } private void AddTrayIcon() { if (trayIcon != null) { return; } trayIcon = new NotifyIcon { Icon = new System.Drawing.Icon("notifyIcon.ico"), Text = "NotifyIconStd" }; trayIcon.Visible = true; ContextMenu menu = new ContextMenu(); MenuItem closeItem = new MenuItem(); closeItem.Text = "Close"; closeItem.Click += new EventHandler(delegate { this.Shutdown(); }); MenuItem addItem = new MenuItem(); addItem.Text = "Menu"; menu.MenuItems.Add(addItem); menu.MenuItems.Add(closeItem); trayIcon.ContextMenu = menu; //设置NotifyIcon的右键弹出菜单 } private void RemoveTrayIcon() { if (trayIcon != null) { trayIcon.Visible = false; trayIcon.Dispose(); trayIcon = null; } } private void ApplicationExit(object sender, ExitEventArgs e) { RemoveTrayIcon(); } }}
该示例程序程序只是在程序启动时,同时启动了一个NotifyIcon,没有其他主程序界面,可以在MenuItem的事件中添加关于弹出其他窗口的处理。
- WPF控件--NotifyIcon
- WPF NotifyIcon 实现例子
- NotifyIcon控件 托盘控件
- C# 系统托盘 控件NotifyIcon
- 托盘控件notifyicon恢复窗体
- 托盘控件(NotifyIcon)恢复窗体
- WPF NotifyIcon ContextMenu 右键菜单 样式Style
- NotifyIcon
- 使用NotifyIcon控件创建任务栏托盘
- WPF:如何实现与WindowsForms程序中类似的NotifyIcon
- WPF ,利用Winform库中的NotifyIcon实现托盘小程序
- C#WinForm程序设计——系统托盘NotifyIcon控件
- 多个form窗体调用同一控件,notifyIcon
- C# WinForm中NotifyICon控件的用法【1】
- C# WinForm中NotifyICon控件的用法【2】
- WPF控件
- wpf控件
- WPF控件
- CCNode
- 杨辉三角
- WPF中实现Timer 事件
- 在一个程序中启动另外一个Activity
- 英雄会第一届在线编程大赛:单词博弈 (C++代码) ---miss若尘
- WPF控件--NotifyIcon
- c#值类型和引用类型的区别
- Ibatis中parameterMap和MAP类型的Result的应用
- WPF初探——利用Winform库中的NotifyIcon实现托盘小程序
- 电容滤波的两个要点
- linux(三) 文件搜索和帮助
- jquery垂直公告滚动
- LLVM 3.3完全兼容C++11
- 电容