本文整理汇总了C#中System.Windows.Forms.NotifyIcon类的典型用法代码示例。如果您正苦于以下问题:C# NotifyIcon类的具体用法?C# NotifyIcon怎么用?C# NotifyIcon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NotifyIcon类属于System.Windows.Forms命名空间,在下文中一共展示了NotifyIcon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShellView
public ShellView()
{
InitializeComponent();
// Check if there was instance before this. If there was-close the current one.
if (ProcessUtilities.ThisProcessIsAlreadyRunning())
{
ProcessUtilities.SetFocusToPreviousInstance("Carnac");
Application.Current.Shutdown();
}
var item = new MenuItem
{
Text = "Exit"
};
item.Click += (sender, args) => Close();
var iconStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Carnac.icon.embedded.ico");
var ni = new NotifyIcon
{
Icon = new Icon(iconStream),
ContextMenu = new ContextMenu(new[] { item })
};
ni.Click += NotifyIconClick;
ni.Visible = true;
}
示例2: Notificator
public Notificator(IEventLogger eventLogger, ISettingsManager settingsManager)
{
_eventLogger = eventLogger;
_settingsManager = settingsManager;
var menuItem = new MenuItem(Strings.Exit);
menuItem.Click += menuItem_Click;
var contextMenu = new ContextMenu(new[] {menuItem});
_notifyIcon = new NotifyIcon
{
Icon = new Icon("TryIcon.ico"),
Visible = true,
BalloonTipTitle = Strings.Caution,
Text = Strings.Initializing,
ContextMenu = contextMenu
};
var oneRunTimer = new Timer(3000)
{
AutoReset = false,
Enabled = true
};
oneRunTimer.Elapsed += _timer_Elapsed; // runs only once after aplication start
var timer = new Timer(60000)
{
AutoReset = true,
Enabled = true
};
timer.Elapsed += _timer_Elapsed;
}
示例3: MainWindow
public MainWindow()
{
InitializeComponent();
this.notifyIcon = new NotifyIcon();
contextMenu = new ContextMenu();
MenuItem refreshItem = new MenuItem();
refreshItem.Click += new System.EventHandler(this.refreshQuestionNo);
refreshItem.Text = "Refresh";
contextMenu.MenuItems.Add(refreshItem);
MenuItem openItem = new MenuItem();
openItem.Click += new System.EventHandler(this.showApp);
openItem.Text = "Show";
contextMenu.MenuItems.Add(openItem);
MenuItem exitItem = new MenuItem();
exitItem.Click += new System.EventHandler(this.exitApp);
exitItem.Text = "Exit";
contextMenu.MenuItems.Add(exitItem);
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
}
示例4: Main
private static void Main()
{
DefaultMediaDevice = new MMDeviceEnumerator().GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
DefaultMediaDevice.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification);
TrayIcon = new NotifyIcon();
TrayIcon.Icon = IconFromVolume();
TrayIcon.Text = ToolTipFromVolume();
TrayIcon.MouseClick += new MouseEventHandler(TrayIcon_MouseClick);
TrayIcon.MouseDoubleClick += new MouseEventHandler(TrayIcon_MouseDoubleClick);
TrayIcon.Visible = true;
TrayIcon.ContextMenu = new ContextMenu();
TrayIcon.ContextMenu.MenuItems.Add(new MenuItem("Open Volume Mixer", (o, e) => { Process.Start(SystemDir + "sndvol.exe"); }));
TrayIcon.ContextMenu.MenuItems.Add(new MenuItem("-"));
TrayIcon.ContextMenu.MenuItems.Add(new MenuItem("Playback devices", (o, e) => { Process.Start(SystemDir + "rundll32.exe", @"Shell32.dll,Control_RunDLL mmsys.cpl,,playback"); }));
TrayIcon.ContextMenu.MenuItems.Add(new MenuItem("Recording devices", (o, e) => { Process.Start(SystemDir + "rundll32.exe", @"Shell32.dll,Control_RunDLL mmsys.cpl,,recording"); }));
TrayIcon.ContextMenu.MenuItems.Add(new MenuItem("Sounds", (o, e) => { Process.Start(SystemDir + "rundll32.exe", @"Shell32.dll,Control_RunDLL mmsys.cpl,,sounds"); }));
TrayIcon.ContextMenu.MenuItems.Add(new MenuItem("-"));
TrayIcon.ContextMenu.MenuItems.Add(new MenuItem("Volume control options", (o, e) => { Process.Start(SystemDir + "sndvol.exe", "-p"); }));
SingleClickWindow = new Timer();
SingleClickWindow.Interval = SystemInformation.DoubleClickTime;
SingleClickWindow.Tick += (o, e) =>
{
SingleClickWindow.Stop();
StartVolControl();
};
Application.Run();
}
示例5: NotificationIcon
public NotificationIcon()
{
try {
this.InitializePerformanceCounters();
this.InitializePoints();
this.InitializeFont();
this.InitializeBitmap();
this.InitializeGraphics();
this.InitializeTimer();
notifyIconCpu = new NotifyIcon();
notifyIconRam = new NotifyIcon();
Icon iconCpu = this.DrawIconCpu();
Icon iconRam = this.DrawIconRam();
notifyIconCpu.Icon = iconCpu;
notifyIconRam.Icon = iconRam;
iconCpu.Dispose();
iconRam.Dispose();
String text = this.DrawText();
notifyIconCpu.Text = text;
notifyIconRam.Text = text;
notifyIconCpu.ContextMenu = this.InitializeMenu();
notifyIconRam.ContextMenu = this.InitializeMenu();
notifyIconCpu.Visible = true;
notifyIconRam.Visible = true;
} catch (Exception exception) {
//MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
示例6: SysTrayMenu
public SysTrayMenu()
{
InitializeComponent();
this.ClientSize = new System.Drawing.Size(FORM_WIDTH, Screen.PrimaryScreen.WorkingArea.Height);
this.LostFocus += (object sender, EventArgs e) => MoveOutScreen();
MoveOutScreen();
trayMenu = new ContextMenu();
trayMenu.MenuItems.Add("Exit", OnExit);
trayMenu.MenuItems.Add("Show", OnShow);
trayIcon = new NotifyIcon();
trayIcon.Text = "eClipx";
trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
trayIcon.ContextMenu = trayMenu;
trayIcon.Visible = true;
KeyboardHook.CallWhen(true, true, Keys.X, GlobalHookKeyPress);
Common.MyHandle = Handle;
CurrentApp.StartWatcher();
clipboardItems = new MruList<int, ClipBoardElement>(CACHE_SIZE);
controlItems = new List<ItemControl>(CACHE_SIZE);
nextClipboardViewer = (IntPtr)User32.SetClipboardViewer((int)this.Handle);
}
示例7: GUI
public GUI()
{
InitializeComponent();
RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 0, (int)Keys.PrintScreen);
// Create a simple tray menu with only one item.
trayMenu = new ContextMenu();
trayMenu.MenuItems.Add("Exit", OnExit);
// Create a tray icon. In this example we use a
// standard system icon for simplicity, but you
// can of course use your own custom icon too.
trayIcon = new NotifyIcon();
trayIcon.Text = "PRTSC_TO_FILE";
trayIcon.Icon = Properties.Resources.MainIcon;
// Add menu to tray icon and show it.
trayIcon.ContextMenu = trayMenu;
trayIcon.Visible = true;
//Make .bmp format default
imageFormatList.SelectedIndex = 0;
//Make count output default
outputFormatCombo.SelectedIndex = 0;
startHiddenCheckBox.Checked = readRegistry();
}
示例8: btnLogin_Click
private void btnLogin_Click(object sender, EventArgs e)
{
string response = network.HttpPost("http://www.status3gaming.com/gmtool/", "user=" + txtUsername.Text + "&pass=" + txtPassword.Text);
if(response == "0"){
MessageBox.Show("Failed Login", "Response", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (Regex.IsMatch(response, "[0-9A-Fa-f]{40}"))
{
Program.SetHash(response);
MessageBox.Show("Successfully Logged In", "Response", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Visible = false;
//Create Context Menu for system tray.
sysTrayMenu = new ContextMenu();
sysTrayMenu.MenuItems.Add("Check for new tickets...", OnRefresh);
sysTrayMenu.MenuItems.Add("Quit", OnExit);
sysTrayIcon = new NotifyIcon();
sysTrayIcon.Text = "GM Tool";
sysTrayIcon.Icon = Properties.Resources.Tray;
// Add menu to tray icon and show it.
sysTrayIcon.ContextMenu = sysTrayMenu;
sysTrayIcon.Visible = true;
sysTrayIcon.BalloonTipClicked += new EventHandler(sysTrayIcon_BaloonTipClicked);
sysTrayIcon.ShowBalloonTip(5000, "GM Tool", "Tray Monitor Active", ToolTipIcon.None);
timer.Start();
}
}
示例9: ProcessIcon
public ProcessIcon(string name)
{
ni = new NotifyIcon();
ni.ContextMenuStrip = new ContextMenuBuilder().GetDefaultMenu();
ni.Text = name;
ni.Icon = Properties.Resources.icon;
}
示例10: MocsForm
public MocsForm()
{
InitializeComponent();
_configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
_notifyIcon = new NotifyIcon();
_notifyIcon.Text = "Mocs Notification";
_notifyIcon.Visible = true;
_notifyIcon.Icon = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("MocsClient.sync.ico"));
_notifyIcon.DoubleClick += new EventHandler(_notifyIcon_DoubleClick);
// Old school balloon tip
//_notifyIcon.BalloonTipClicked += new EventHandler(_notifyIcon_BalloonTipClicked);
BuildContextMenu();
_notifyIcon.ContextMenu = _contextMenu;
_messageInterceptor = new MessageInterceptor();
_messageInterceptor.Initialize();
dataGridViewNotification.MouseWheel += new MouseEventHandler(dataGridViewNotification_MouseWheel);
dataGridViewNotification.KeyDown += new KeyEventHandler(dataGridViewNotification_KeyDown);
dataGridViewNotification.KeyUp += new KeyEventHandler(dataGridViewNotification_KeyUp);
}
示例11: ApplicationContext
public ApplicationContext()
{
if (Properties.Settings.Default.CallUpgrade)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.CallUpgrade = false;
Properties.Settings.Default.Save();
}
_components = new System.ComponentModel.Container();
_notifyIcon = new NotifyIcon(_components)
{
ContextMenuStrip = new ContextMenuStrip(),
Visible = true
};
_notifyIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem("Settings", null, new EventHandler(MenuSettingsItem_Click)));
_notifyIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem("Exit", null, new EventHandler(MenuExitItem_Click)));
_buddies = new Buddies();
_housekeepingTimer = new System.Windows.Forms.Timer();
_housekeepingTimer.Interval = 5000;
_housekeepingTimer.Tick += HousekeepingTimer_Tick;
HousekeepingTimer_Tick(null, null); // tick anyway enables timer when finished
_trackerStatus = TrackerStatus.OK;
if (trackersConfigured())
{
_trackerStatus = TrackerStatus.UNKNOWN;
UpdateTrackerSetting();
}
_viewModel = new ViewModel(_buddies);
}
示例12: SysTrayContext
public SysTrayContext()
{
container = new System.ComponentModel.Container();
notifyIcon = new NotifyIcon(this.container);
notifyIcon.Icon = forever.icon;
notifyIcon.Text = "Forever";
notifyIcon.Visible = true;
//Instantiate the context menu and items
contextMenu = new ContextMenuStrip();
menuItemExit = new ToolStripMenuItem();
//Attach the menu to the notify icon
notifyIcon.ContextMenuStrip = contextMenu;
menuItemExit.Text = "Exit";
menuItemExit.Click += new EventHandler(menuItemExit_Click);
contextMenu.Items.Add(menuItemExit);
timer = new Timer(this.container);
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
示例13: NotifyIconHelper
/// <summary>
/// 构造 NotifyIconHelper 的新实例。
/// </summary>
/// <param name="mainForm">应用程序主窗体。</param>
/// <param name="notHandleClosingEvent">是否不让 NotifyIconHelper 处理主窗体的 FormClosing 事件。
/// <remarks>
/// 缺省情况下此参数应为 False,即 NotifyIconHelper 总是通过处理主窗体的 FormClosing 事件达到让主窗体在关闭后
/// 驻留系统托盘区的目的。但特殊情况下,应用程序可能会自己处理主窗体的的 FormClosing 事件,此时应设置此属性为 True。
/// </remarks>
/// </param>
/// <param name="showPromptWhenClosing">是否在窗体关闭时给用户以提示,仅当 NotHandleClosingEvent = False 时有效。</param>
public NotifyIconHelper( Form mainForm, bool notHandleClosingEvent, bool showPromptWhenClosing )
{
_mainForm = mainForm;
_showPromptWhenClosing = showPromptWhenClosing;
_imgLst = new ImageList();
_imgLst.Images.Add( _mainForm.Icon );
Image img = Image.FromHbitmap( _mainForm.Icon.ToBitmap().GetHbitmap() );
_contextMenu = new ContextMenuStrip();
_contextMenu.Items.Add( new ToolStripMenuItem( Resources.MenuShowMainForm, img, OnShowMainForm ) );
_contextMenu.Items.Add( new ToolStripSeparator() );
_contextMenu.Items.Add( new ToolStripMenuItem( Resources.MenuExit, null, OnExitApp ) );
_notifyIcon = new NotifyIcon();
_notifyIcon.Icon = GetAppIcon();
_notifyIcon.Text = _mainForm.Text;
_notifyIcon.Visible = true;
_notifyIcon.ContextMenuStrip = _contextMenu;
_notifyIcon.MouseDown += _notifyIcon_MouseDown;
_mainForm.FormClosed += _mainForm_FormClosed;
if( notHandleClosingEvent == false )
_mainForm.FormClosing += new FormClosingEventHandler( _mainForm_FormClosing );
}
示例14: ConnectStatus
public ConnectStatus(MainWindow window)
{
this.window = window;
icon = new NotifyIcon();
icon.Visible = true;
icon.DoubleClick += (sender, e) => {
window.WindowState = System.Windows.WindowState.Normal;
window.Activate();
};
var menu = new ContextMenu();
menu.MenuItems.Add(resources["AddRules"] as string, (sender, e) => {
Rules.OpenEditor(false);
});
menu.MenuItems.Add(resources["Exit"] as string, (sender, e) => {
System.Windows.Application.Current.Shutdown();
});
icon.ContextMenu = menu;
SetStatus(Status.Stopped, resources["NotConnected"] as string);
System.Windows.Application.Current.Exit += (sender, e) => {
icon.Dispose();
};
}
示例15: Initialize
public void Initialize()
{
m_Notify = new NotifyIcon();
m_Notify.Visible = true;
m_Notify.Icon = SystemIcons.Application;
m_Notify.ContextMenu = new ContextMenu(new MenuItem[] { new MenuItem("Exit", tsmiQuit_Click) });
m_Notify.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
try
{
string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), SETTINGS_FOLDER_NAME);
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
WriteSettings(new ConnectionSettings());
}
m_Settings = LoadSettings();
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
}
catch (JsonSerializationException ex)
{
MessageBox.Show("Error interpreting settings. Clearing.");
WriteSettings(new ConnectionSettings());
m_Settings = new ConnectionSettings();
}
btnStart.Enabled = !(m_Settings == null || !m_Settings.IsValid);
btnStop.Enabled = false;
}