国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

WPF中使用NotifyIcon(系統(tǒng)托盤)

2020-04-15 09:13 作者:Tuple_元組  | 我要投稿

說明:本文基于 .Netcore 3.X

一、啟用System.Windows.Forms

因系統(tǒng)托盤功能模塊,定義在System.Windows.Forms.NotifyIcon 中,故需使用System.Windows.Forms。具體方式是在項目文件中,添加“<UseWindowsForms>”內容。

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
? <PropertyGroup>
? ? ? ?<OutputType>WinExe</OutputType>
? ? ? ?<TargetFramework>netcoreapp3.1</TargetFramework>
? ? ? ?<UseWPF>true</UseWPF>
? ? ? ?<UseWindowsForms>true</UseWindowsForms>
? ? ? ?<ApplicationIcon>AppRes\Images\App.ico</ApplicationIcon>
? </PropertyGroup>
</Project>

二、在主窗體中添加如下代碼

1.初始化NotifyIcon控件

public MainWindow()
? ?{
? ? ? ?InitializeComponent();
? ? ? ?//系統(tǒng)托盤顯示
? ? ? ?this.notifyIcon = new NotifyIcon();
? ? ? ?this.notifyIcon.BalloonTipText = "系統(tǒng)監(jiān)控中... ...";
? ? ? ?this.notifyIcon.ShowBalloonTip(2000);
? ? ? ?this.notifyIcon.Text = "系統(tǒng)監(jiān)控中... ...";
? ? ? ?//this.notifyIcon.Icon = new System.Drawing.Icon(@"AppIcon.ico");
? ? ? ?this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
? ? ? ?this.notifyIcon.Visible = true;
? ? ? ?//托盤右鍵菜單項
? ? ? ?this.notifyIcon.ContextMenuStrip = new ContextMenuStrip();
? ? ? ?this.notifyIcon.ContextMenuStrip.Items.Add("顯示主窗口", null, (sender, eventArgs) => {
? ? ? ? ? ?this.Visibility = System.Windows.Visibility.Visible;
? ? ? ? ? ?this.ShowInTaskbar = true;
? ? ? ? ? ?this.Activate();
? ? ? ?});
? ? ? ?this.notifyIcon.ContextMenuStrip.Items.Add("關閉程序", null, (sender, eventArgs) => {
? ? ? ? ? ?this.notifyIcon.Dispose();
? ? ? ? ? ?System.Windows.Application.Current.Shutdown(0);
? ? ? ?});
? ? ? ?//托盤雙擊響應
? ? ? ?this.notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler((o, e) =>
? ? ? ? {
? ? ? ? ? ?if (e.Button == MouseButtons.Left)
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?this.notifyIcon.ContextMenuStrip.Items[0].PerformClick();
? ? ? ? ? ? ? ?}
? ? ? ?}); ? ? ? ? ? ?
? ?}

2.在主窗口頂部自定義的工具欄的關閉按鈕中添加以下代碼

? ?this.ShowInTaskbar = false;
? ?this.Visibility = System.Windows.Visibility.Hidden;
? ?this.notifyIcon.ShowBalloonTip(20, "信息:", "工作平臺已隱藏在這兒。", ToolTipIcon.Info);


**歡迎大家留言交流**

WPF中使用NotifyIcon(系統(tǒng)托盤)的評論 (共 條)

分享到微博請遵守國家法律
盐山县| 岳阳县| 遂昌县| 历史| 桃源县| 古田县| 绵竹市| 乐山市| 卓尼县| 民县| 金寨县| 饶平县| 岑巩县| 临西县| 郓城县| 陇西县| 黔西县| 大渡口区| 汉源县| 化州市| 十堰市| 定远县| 额济纳旗| 苗栗市| 曲靖市| 东明县| 紫阳县| 西峡县| 霍州市| 砚山县| 岳池县| 常州市| 宽甸| 雅江县| 绥芬河市| 平山县| 三门峡市| 乐东| 东乡县| 秦安县| 宝应县|