Еще рефакторинга
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JiraTimeBotForm.UI.Tray
|
||||
{
|
||||
public interface ITrayMenu
|
||||
{
|
||||
NotifyIcon Create(frmMain form);
|
||||
void Show();
|
||||
void Hide();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JiraTimeBotForm.UI.Tray
|
||||
{
|
||||
public static class RestoreFromTray {
|
||||
[DllImport( "user32.dll" )]
|
||||
private static extern int ShowWindow( IntPtr hWnd, uint Msg );
|
||||
|
||||
private const uint SW_RESTORE = 0x09;
|
||||
|
||||
public static void Restore( this Form form )
|
||||
{
|
||||
if (form.WindowState == FormWindowState.Minimized)
|
||||
{
|
||||
ShowWindow(form.Handle, SW_RESTORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JiraTimeBotForm.UI.Tray
|
||||
{
|
||||
public class TrayMenu: ITrayMenu
|
||||
{
|
||||
private NotifyIcon _trayIcon;
|
||||
|
||||
public NotifyIcon Create(frmMain form)
|
||||
{
|
||||
var trayMenu = new ContextMenu();
|
||||
trayMenu.MenuItems.Add("Exit", OnExit);
|
||||
|
||||
_trayIcon = new NotifyIcon
|
||||
{
|
||||
Text = "JiraTimeBot",
|
||||
Icon = form.Icon,
|
||||
ContextMenu = trayMenu,
|
||||
Visible = false,
|
||||
Tag = form
|
||||
};
|
||||
_trayIcon.Click += btnTray_Click;
|
||||
_trayIcon.DoubleClick += btnTray_Click;
|
||||
|
||||
return _trayIcon;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
_trayIcon.Visible = true;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
_trayIcon.Visible = false;
|
||||
}
|
||||
|
||||
private void OnExit(object sender, EventArgs e)
|
||||
{
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private void btnTray_Click(object sender, EventArgs e)
|
||||
{
|
||||
var icon = (NotifyIcon) sender;
|
||||
var form = (frmMain) icon.Tag;
|
||||
form.Visible = true;
|
||||
form.Activate();
|
||||
form.BringToFront();
|
||||
RestoreFromTray.Restore(form);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user