FrmToolbox: Close to tray and exit button.
This commit is contained in:
64
VAR.Toolbox/UI/FrmToolbox.Designer.cs
generated
64
VAR.Toolbox/UI/FrmToolbox.Designer.cs
generated
@@ -28,6 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.btnBase64 = new System.Windows.Forms.Button();
|
||||
this.btnProxyCmd = new System.Windows.Forms.Button();
|
||||
this.btnWebcam = new System.Windows.Forms.Button();
|
||||
@@ -35,16 +36,17 @@
|
||||
this.lblToolbox = new System.Windows.Forms.Label();
|
||||
this.pnlSuspension1 = new VAR.Toolbox.UI.PnlSuspension();
|
||||
this.pnlCover1 = new VAR.Toolbox.UI.PnlCover();
|
||||
this.niTray = new System.Windows.Forms.NotifyIcon(this.components);
|
||||
this.btnExit = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnBase64
|
||||
//
|
||||
this.btnBase64.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnBase64.Location = new System.Drawing.Point(13, 80);
|
||||
this.btnBase64.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnBase64.Location = new System.Drawing.Point(9, 52);
|
||||
this.btnBase64.Name = "btnBase64";
|
||||
this.btnBase64.Size = new System.Drawing.Size(238, 52);
|
||||
this.btnBase64.Size = new System.Drawing.Size(159, 34);
|
||||
this.btnBase64.TabIndex = 0;
|
||||
this.btnBase64.Text = "Base64";
|
||||
this.btnBase64.UseVisualStyleBackColor = true;
|
||||
@@ -54,10 +56,9 @@
|
||||
//
|
||||
this.btnProxyCmd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnProxyCmd.Location = new System.Drawing.Point(13, 142);
|
||||
this.btnProxyCmd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnProxyCmd.Location = new System.Drawing.Point(9, 92);
|
||||
this.btnProxyCmd.Name = "btnProxyCmd";
|
||||
this.btnProxyCmd.Size = new System.Drawing.Size(238, 55);
|
||||
this.btnProxyCmd.Size = new System.Drawing.Size(159, 36);
|
||||
this.btnProxyCmd.TabIndex = 1;
|
||||
this.btnProxyCmd.Text = "ProxyCmd";
|
||||
this.btnProxyCmd.UseVisualStyleBackColor = true;
|
||||
@@ -67,10 +68,9 @@
|
||||
//
|
||||
this.btnWebcam.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnWebcam.Location = new System.Drawing.Point(13, 207);
|
||||
this.btnWebcam.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnWebcam.Location = new System.Drawing.Point(9, 135);
|
||||
this.btnWebcam.Name = "btnWebcam";
|
||||
this.btnWebcam.Size = new System.Drawing.Size(238, 55);
|
||||
this.btnWebcam.Size = new System.Drawing.Size(159, 36);
|
||||
this.btnWebcam.TabIndex = 2;
|
||||
this.btnWebcam.Text = "Webcam";
|
||||
this.btnWebcam.UseVisualStyleBackColor = true;
|
||||
@@ -80,9 +80,10 @@
|
||||
//
|
||||
this.btnTunnelTCP.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnTunnelTCP.Location = new System.Drawing.Point(13, 270);
|
||||
this.btnTunnelTCP.Location = new System.Drawing.Point(9, 175);
|
||||
this.btnTunnelTCP.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.btnTunnelTCP.Name = "btnTunnelTCP";
|
||||
this.btnTunnelTCP.Size = new System.Drawing.Size(238, 55);
|
||||
this.btnTunnelTCP.Size = new System.Drawing.Size(159, 36);
|
||||
this.btnTunnelTCP.TabIndex = 5;
|
||||
this.btnTunnelTCP.Text = "TunnelTCP";
|
||||
this.btnTunnelTCP.UseVisualStyleBackColor = true;
|
||||
@@ -93,9 +94,10 @@
|
||||
this.lblToolbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.lblToolbox.Font = new System.Drawing.Font("Arial Narrow", 28F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lblToolbox.Location = new System.Drawing.Point(12, 9);
|
||||
this.lblToolbox.Location = new System.Drawing.Point(9, 9);
|
||||
this.lblToolbox.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.lblToolbox.Name = "lblToolbox";
|
||||
this.lblToolbox.Size = new System.Drawing.Size(239, 66);
|
||||
this.lblToolbox.Size = new System.Drawing.Size(159, 40);
|
||||
this.lblToolbox.TabIndex = 6;
|
||||
this.lblToolbox.Text = "Toolbox";
|
||||
this.lblToolbox.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
@@ -104,25 +106,46 @@
|
||||
//
|
||||
this.pnlSuspension1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.pnlSuspension1.Location = new System.Drawing.Point(18, 505);
|
||||
this.pnlSuspension1.Location = new System.Drawing.Point(10, 323);
|
||||
this.pnlSuspension1.Margin = new System.Windows.Forms.Padding(1);
|
||||
this.pnlSuspension1.Name = "pnlSuspension1";
|
||||
this.pnlSuspension1.Size = new System.Drawing.Size(232, 175);
|
||||
this.pnlSuspension1.Size = new System.Drawing.Size(155, 114);
|
||||
this.pnlSuspension1.TabIndex = 4;
|
||||
//
|
||||
// pnlCover1
|
||||
//
|
||||
this.pnlCover1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.pnlCover1.Location = new System.Drawing.Point(18, 351);
|
||||
this.pnlCover1.Location = new System.Drawing.Point(10, 225);
|
||||
this.pnlCover1.Margin = new System.Windows.Forms.Padding(1);
|
||||
this.pnlCover1.Name = "pnlCover1";
|
||||
this.pnlCover1.Size = new System.Drawing.Size(232, 148);
|
||||
this.pnlCover1.Size = new System.Drawing.Size(155, 96);
|
||||
this.pnlCover1.TabIndex = 3;
|
||||
//
|
||||
// niTray
|
||||
//
|
||||
this.niTray.Text = "VAR.Toolbox";
|
||||
this.niTray.Visible = true;
|
||||
this.niTray.MouseClick += new System.Windows.Forms.MouseEventHandler(this.niTray_MouseClick);
|
||||
//
|
||||
// btnExit
|
||||
//
|
||||
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnExit.Location = new System.Drawing.Point(12, 441);
|
||||
this.btnExit.Name = "btnExit";
|
||||
this.btnExit.Size = new System.Drawing.Size(152, 29);
|
||||
this.btnExit.TabIndex = 7;
|
||||
this.btnExit.Text = "Exit";
|
||||
this.btnExit.UseVisualStyleBackColor = true;
|
||||
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
|
||||
//
|
||||
// FrmToolbox
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(263, 692);
|
||||
this.ClientSize = new System.Drawing.Size(175, 482);
|
||||
this.Controls.Add(this.btnExit);
|
||||
this.Controls.Add(this.lblToolbox);
|
||||
this.Controls.Add(this.btnTunnelTCP);
|
||||
this.Controls.Add(this.pnlSuspension1);
|
||||
@@ -131,7 +154,6 @@
|
||||
this.Controls.Add(this.btnProxyCmd);
|
||||
this.Controls.Add(this.btnBase64);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "FrmToolbox";
|
||||
this.Text = "Toolbox";
|
||||
@@ -151,6 +173,8 @@
|
||||
private PnlSuspension pnlSuspension1;
|
||||
private System.Windows.Forms.Button btnTunnelTCP;
|
||||
private System.Windows.Forms.Label lblToolbox;
|
||||
private System.Windows.Forms.NotifyIcon niTray;
|
||||
private System.Windows.Forms.Button btnExit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,14 @@ namespace VAR.Toolbox.UI
|
||||
{
|
||||
public partial class FrmToolbox : Form
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private bool _closing = false;
|
||||
|
||||
#endregion Declarations
|
||||
|
||||
#region Form life cycle
|
||||
|
||||
public FrmToolbox()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -18,7 +26,53 @@ namespace VAR.Toolbox.UI
|
||||
|
||||
private void FrmToolbox_Load(object sender, EventArgs e)
|
||||
{
|
||||
Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
|
||||
Icon ico = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
|
||||
Icon = ico;
|
||||
niTray.Icon = ico;
|
||||
}
|
||||
|
||||
protected override void OnFormClosing(FormClosingEventArgs e)
|
||||
{
|
||||
if (e.CloseReason == CloseReason.WindowsShutDown || _closing)
|
||||
{
|
||||
base.OnFormClosing(e);
|
||||
return;
|
||||
}
|
||||
|
||||
HideChildWindows();
|
||||
Hide();
|
||||
e.Cancel = true;
|
||||
}
|
||||
|
||||
#endregion Form life cycle
|
||||
|
||||
#region UI events
|
||||
|
||||
private void DragWindow_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
User32.ReleaseCapture();
|
||||
User32.SendMessage(Handle, User32.WM_NCLBUTTONDOWN, User32.HT_CAPTION, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnExit_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult dialogResult = MessageBox.Show("Are you sure want to exit?", "Exit?", MessageBoxButtons.YesNo);
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
_closing = true;
|
||||
CloseChildWindows();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void niTray_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
Show();
|
||||
ShowChildWindows();
|
||||
WindowState = FormWindowState.Normal;
|
||||
}
|
||||
|
||||
private void btnBase64_Click(object sender, EventArgs e)
|
||||
@@ -41,14 +95,8 @@ namespace VAR.Toolbox.UI
|
||||
CreateWindow(typeof(FrmTunnelTCP));
|
||||
}
|
||||
|
||||
private void DragWindow_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
User32.ReleaseCapture();
|
||||
User32.SendMessage(Handle, User32.WM_NCLBUTTONDOWN, User32.HT_CAPTION, 0);
|
||||
}
|
||||
}
|
||||
#endregion UI events
|
||||
|
||||
#region Window handling
|
||||
|
||||
private Form CreateWindow(Type type)
|
||||
@@ -77,10 +125,7 @@ namespace VAR.Toolbox.UI
|
||||
|
||||
private void FrmToolbox_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
while (_forms.Count > 0)
|
||||
{
|
||||
_forms[0].Close();
|
||||
}
|
||||
CloseChildWindows();
|
||||
}
|
||||
|
||||
private bool _wasMinimized = false;
|
||||
@@ -90,18 +135,36 @@ namespace VAR.Toolbox.UI
|
||||
if (FormWindowState.Minimized == WindowState)
|
||||
{
|
||||
_wasMinimized = true;
|
||||
foreach(Form frm in _forms)
|
||||
{
|
||||
frm.Hide();
|
||||
}
|
||||
HideChildWindows();
|
||||
}
|
||||
if (FormWindowState.Normal == WindowState && _wasMinimized)
|
||||
{
|
||||
_wasMinimized = false;
|
||||
foreach (Form frm in _forms)
|
||||
{
|
||||
frm.Show();
|
||||
}
|
||||
ShowChildWindows();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseChildWindows()
|
||||
{
|
||||
while (_forms.Count > 0)
|
||||
{
|
||||
_forms[0].Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowChildWindows()
|
||||
{
|
||||
foreach (Form frm in _forms)
|
||||
{
|
||||
frm.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void HideChildWindows()
|
||||
{
|
||||
foreach (Form frm in _forms)
|
||||
{
|
||||
frm.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user