本文整理汇总了C#中System.Windows.Forms.NotifyIcon.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Windows.Forms.NotifyIcon.Dispose方法的具体用法?C# System.Windows.Forms.NotifyIcon.Dispose怎么用?C# System.Windows.Forms.NotifyIcon.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.NotifyIcon
的用法示例。
在下文中一共展示了System.Windows.Forms.NotifyIcon.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupTrayIcon
private static void SetupTrayIcon(string logFileName)
{
// Create tray icon
var components = new System.ComponentModel.Container();
var notifyIcon = new System.Windows.Forms.NotifyIcon(components);
notifyIcon.Text = "Paradox Connection Router";
notifyIcon.Icon = Properties.Resources.Logo;
notifyIcon.Visible = true;
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
if (!string.IsNullOrEmpty(logFileName))
{
var showLogMenuItem = new System.Windows.Forms.MenuItem("Show &Log");
showLogMenuItem.Click += (sender, args) => OnShowLogClick(logFileName);
notifyIcon.ContextMenu.MenuItems.Add(showLogMenuItem);
notifyIcon.BalloonTipClicked += (sender, args) => OnShowLogClick(logFileName);
}
var openConsoleMenuItem = new System.Windows.Forms.MenuItem("Open Console");
openConsoleMenuItem.Click += (sender, args) => OnOpenConsoleClick((System.Windows.Forms.MenuItem)sender);
notifyIcon.ContextMenu.MenuItems.Add(openConsoleMenuItem);
var exitMenuItem = new System.Windows.Forms.MenuItem("E&xit");
exitMenuItem.Click += (sender, args) => OnExitClick();
notifyIcon.ContextMenu.MenuItems.Add(exitMenuItem);
GlobalLogger.GlobalMessageLogged += (logMessage) =>
{
System.Windows.Forms.ToolTipIcon toolTipIcon;
switch (logMessage.Type)
{
case LogMessageType.Debug:
case LogMessageType.Verbose:
case LogMessageType.Info:
toolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
break;
case LogMessageType.Warning:
toolTipIcon = System.Windows.Forms.ToolTipIcon.Warning;
break;
case LogMessageType.Error:
case LogMessageType.Fatal:
toolTipIcon = System.Windows.Forms.ToolTipIcon.Error;
break;
default:
throw new ArgumentOutOfRangeException();
}
// Display notification (for one second)
notifyIcon.ShowBalloonTip(2000, "Paradox Connection Router", logMessage.ToString(), toolTipIcon);
};
System.Windows.Forms.Application.ApplicationExit += (sender, e) =>
{
notifyIcon.Visible = false;
notifyIcon.Icon = null;
notifyIcon.Dispose();
};
}
示例2: SetupTrayIcon
private static void SetupTrayIcon(string logFileName)
{
// Create tray icon
var components = new System.ComponentModel.Container();
var notifyIcon = new System.Windows.Forms.NotifyIcon(components);
notifyIcon.Text = "Xenko Connection Router";
notifyIcon.Icon = Properties.Resources.Logo;
notifyIcon.Visible = true;
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
if (!string.IsNullOrEmpty(logFileName))
{
var showLogMenuItem = new System.Windows.Forms.MenuItem("Show &Log");
showLogMenuItem.Click += (sender, args) => OnShowLogClick(logFileName);
notifyIcon.ContextMenu.MenuItems.Add(showLogMenuItem);
notifyIcon.BalloonTipClicked += (sender, args) => OnShowLogClick(logFileName);
}
var openConsoleMenuItem = new System.Windows.Forms.MenuItem("Open Console");
openConsoleMenuItem.Click += (sender, args) => OnOpenConsoleClick((System.Windows.Forms.MenuItem)sender);
notifyIcon.ContextMenu.MenuItems.Add(openConsoleMenuItem);
var exitMenuItem = new System.Windows.Forms.MenuItem("E&xit");
exitMenuItem.Click += (sender, args) => OnExitClick();
notifyIcon.ContextMenu.MenuItems.Add(exitMenuItem);
GlobalLogger.GlobalMessageLogged += (logMessage) =>
{
// Log only warning, errors and more
if (logMessage.Type < LogMessageType.Warning)
return;
var toolTipIcon = logMessage.Type < LogMessageType.Error ? System.Windows.Forms.ToolTipIcon.Warning : System.Windows.Forms.ToolTipIcon.Error;
// Display notification (for two second)
notifyIcon.ShowBalloonTip(2000, "Xenko Connection Router", logMessage.ToString(), toolTipIcon);
};
System.Windows.Forms.Application.ApplicationExit += (sender, e) =>
{
notifyIcon.Visible = false;
notifyIcon.Icon = null;
notifyIcon.Dispose();
};
}
示例3: InitializeNotifyIcon
private void InitializeNotifyIcon()
{
NotifyIcon = new System.Windows.Forms.NotifyIcon
{
Text = "Patchy",
Icon = new System.Drawing.Icon(Application.GetResourceStream(
new Uri("pack://application:,,,/Patchy;component/Images/patchy.ico" )).Stream),
Visible = true
};
NotifyIcon.DoubleClick += NotifyIconClick;
NotifyIcon.BalloonTipClicked += NotifyIconBalloonTipClicked;
var menu = new System.Windows.Forms.ContextMenu();
menu.MenuItems.Add("Add Torrent", (s, e) => ExecuteNew(null, null));
menu.MenuItems.Add("Exit", (s, e) =>
{
NotifyIcon.Dispose();
AllowClose = true;
Close();
});
NotifyIcon.ContextMenu = menu;
}
示例4: Dispose
private void Dispose(bool disposing)
{
if (!disposed)
{
disposed = true;
var notifyIcon = this.notifyIcon;
this.notifyIcon = null;
if (notifyIcon != null)
{
notifyIcon.Dispose();
}
GC.SuppressFinalize(this);
}
}