This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
linear-app-launcher/Windows/Forms/AForm.cs

405 lines
16 KiB
C#
Raw Normal View History

2020-03-28 02:54:08 +00:00
using System;
2020-05-16 12:25:59 +00:00
using System.ComponentModel;
2020-03-28 02:54:08 +00:00
using System.Drawing;
using System.Windows.Forms;
namespace AppLauncher.Windows.Forms
{
public class AForm : Form
{
2020-05-17 02:24:46 +00:00
protected readonly Color borderColour = Color.FromArgb(232, 231, 236);
protected readonly int borderWidth = 1;
2020-10-20 21:42:40 +00:00
protected readonly Color backColour = Color.FromArgb(254, 254, 254);
2020-05-17 02:24:46 +00:00
protected readonly Color titleBarColour = Color.FromArgb(237, 240, 247);
2020-10-20 21:42:40 +00:00
protected readonly Color titleColour = Color.FromArgb(156, 158, 171);
2020-05-17 02:24:46 +00:00
protected readonly int titleBarHeight = 56;
2020-05-16 12:25:59 +00:00
2020-05-17 02:24:46 +00:00
private bool isDragging = false;
private Point startPosition = new Point();
protected bool isBusy = false;
2020-05-17 03:31:25 +00:00
protected internal RyzStudio.Windows.Forms.TImageBox imageBox3;
protected internal RyzStudio.Windows.Forms.TImageBox imageBox2;
protected internal RyzStudio.Windows.Forms.TImageBox imageBox1;
private NotifyIcon notifyIcon1;
private Panel panel1;
2020-05-18 19:45:25 +00:00
private ContextMenuStrip contextMenuStrip1;
private ToolStripMenuItem exitToolStripMenuItem;
private IContainer components;
2020-03-28 02:54:08 +00:00
public AForm() : base()
{
2020-05-17 03:31:25 +00:00
InitializeComponent();
2020-03-28 02:54:08 +00:00
if (!this.DesignMode)
{
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.Manual;
}
2020-05-18 23:17:22 +00:00
2020-10-20 21:42:40 +00:00
this.BackColor = backColour;
this.Padding = new Padding(0);
notifyIcon1.Text = Application.ProductName;
2020-03-28 02:54:08 +00:00
}
2020-05-17 03:31:25 +00:00
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.SuspendLayout();
2020-05-17 03:31:25 +00:00
imageBox3.Left = this.DisplayRectangle.Width - imageBox3.Width - 17;
imageBox3.Top = 18;
2020-05-17 03:31:25 +00:00
imageBox3.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
imageBox2.Left = imageBox3.Left - imageBox2.Width - 8;
imageBox2.Top = 18;
imageBox2.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
imageBox1.Left = imageBox2.Left - imageBox1.Width - 8;
imageBox1.Top = 18;
imageBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
panel1.Left = this.DisplayRectangle.Left;
panel1.Top = this.DisplayRectangle.Height - panel1.Height;
panel1.Width = this.DisplayRectangle.Width;
panel1.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom);
2020-10-20 21:42:40 +00:00
if (this.DesignMode)
{
imageBox1.Visible = imageBox2.Visible = imageBox3.Visible = false;
panel1.Visible = false;
}
2020-05-17 03:31:25 +00:00
this.ResumeLayout();
}
2020-05-16 12:25:59 +00:00
protected override void OnMouseClick(MouseEventArgs e)
2020-05-10 10:03:55 +00:00
{
2020-05-16 12:25:59 +00:00
base.OnMouseClick(e);
2020-03-28 02:54:08 +00:00
2020-05-17 02:24:46 +00:00
bool isLabel = ((e.Location.X >= 0) && (e.Location.X <= this.Width) && (e.Location.Y >= 0) && (e.Location.Y <= titleBarHeight));
2020-03-28 02:54:08 +00:00
2020-05-16 12:25:59 +00:00
if (e.Button == MouseButtons.Left)
{
if (isLabel)
{
// do nothing
}
else
{
// do nothing
}
}
else if (e.Button == MouseButtons.Right)
{
if (isLabel)
{
if (this.TitleContextMenuStrip != null)
{
this.TitleContextMenuStrip.Show(this, e.Location);
}
}
else
{
// do nothing
}
2020-05-10 10:03:55 +00:00
}
}
2020-03-28 02:54:08 +00:00
2020-05-16 12:25:59 +00:00
protected override void OnMouseDown(MouseEventArgs e)
{
2020-05-16 12:25:59 +00:00
base.OnMouseDown(e);
if (e.Button != MouseButtons.Left)
{
return;
}
isDragging = true;
startPosition = e.Location;
}
2020-05-16 12:25:59 +00:00
protected override void OnMouseMove(MouseEventArgs e)
{
2020-05-16 12:25:59 +00:00
base.OnMouseMove(e);
if (isDragging)
{
int x = (this.Location.X + (e.Location.X - startPosition.X));
int y = (this.Location.Y + (e.Location.Y - startPosition.Y));
//this.Location = validateFormLocation(x, y);
this.Location = new Point(x, y);
}
}
2020-05-16 12:25:59 +00:00
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
isDragging = false;
}
2020-05-17 02:24:46 +00:00
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
Rectangle area = new Rectangle(this.DisplayRectangle.X, this.DisplayRectangle.Y, (this.DisplayRectangle.Width - borderWidth), (this.DisplayRectangle.Height - borderWidth));
// border
g.DrawRectangle(new Pen(borderColour, borderWidth), area);
area.Inflate((-1 * borderWidth), (-1 * borderWidth));
g.FillRectangle(new SolidBrush(titleBarColour), area.X, area.Y, (area.Width + area.X), titleBarHeight);
g.DrawLine(new Pen(borderColour, 1), area.X, (titleBarHeight + 1), (area.Width + area.X), (titleBarHeight + 1));
2020-10-20 21:42:40 +00:00
if (!DesignMode) g.DrawImageUnscaled(Properties.Resources.app_icon_24, 17, 17);
2020-05-17 02:24:46 +00:00
2020-10-20 21:42:40 +00:00
if (!DesignMode) TextRenderer.DrawText(g, Application.ProductName, new Font(this.Font.FontFamily, 14F), new Point(58, 17), titleColour);
2020-05-17 02:24:46 +00:00
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Invalidate();
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
2020-10-20 21:42:40 +00:00
public override Color BackColor { get => base.BackColor; set => base.BackColor = value; }
2020-05-17 02:24:46 +00:00
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new FormBorderStyle FormBorderStyle { get => base.FormBorderStyle; set => base.FormBorderStyle = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
2020-10-20 21:42:40 +00:00
public new Padding Padding { get => base.Padding; set => base.Padding = value; }
2020-05-17 02:24:46 +00:00
[Category("Appearance")]
public ContextMenuStrip TitleContextMenuStrip { get; set; } = null;
2020-05-16 12:25:59 +00:00
protected Point DefaultLocation
{
get
{
Point newPosition = new Point(Cursor.Position.X, Cursor.Position.Y);
newPosition.X -= (this.Width / 2);
newPosition.Y -= (this.Height / 2);
newPosition.X = Math.Max(newPosition.X, Screen.PrimaryScreen.WorkingArea.Left);
newPosition.Y = Math.Max(newPosition.Y, Screen.PrimaryScreen.WorkingArea.Top);
return newPosition;
}
}
2020-05-17 03:31:25 +00:00
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AForm));
2020-05-17 03:31:25 +00:00
this.imageBox3 = new RyzStudio.Windows.Forms.TImageBox();
this.imageBox2 = new RyzStudio.Windows.Forms.TImageBox();
this.imageBox1 = new RyzStudio.Windows.Forms.TImageBox();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
2020-05-18 19:45:25 +00:00
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.panel1 = new System.Windows.Forms.Panel();
2020-05-17 03:31:25 +00:00
((System.ComponentModel.ISupportInitialize)(this.imageBox3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.imageBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.imageBox1)).BeginInit();
2020-05-18 19:45:25 +00:00
this.contextMenuStrip1.SuspendLayout();
2020-05-17 03:31:25 +00:00
this.SuspendLayout();
2020-05-18 23:17:22 +00:00
//
2020-05-17 03:31:25 +00:00
// imageBox3
2020-05-18 23:17:22 +00:00
//
2020-05-17 03:31:25 +00:00
this.imageBox3.BackColor = System.Drawing.Color.Transparent;
this.imageBox3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.imageBox3.ErrorImage = null;
this.imageBox3.Image = global::AppLauncher.Resource1.close_20;
this.imageBox3.ImageHover = global::AppLauncher.Resource1.close2_20;
this.imageBox3.ImageNormal = global::AppLauncher.Resource1.close_20;
this.imageBox3.ImageSelected = null;
2020-05-17 03:31:25 +00:00
this.imageBox3.InitialImage = null;
this.imageBox3.IsSelected = false;
this.imageBox3.Location = new System.Drawing.Point(169, 12);
2020-05-17 03:31:25 +00:00
this.imageBox3.Name = "imageBox3";
this.imageBox3.Size = new System.Drawing.Size(20, 20);
2020-05-17 03:31:25 +00:00
this.imageBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.imageBox3.TabIndex = 146;
this.imageBox3.TabStop = false;
this.imageBox3.MouseClick += new System.Windows.Forms.MouseEventHandler(this.imageBox3_MouseClick);
2020-05-18 23:17:22 +00:00
//
// imageBox2
2020-05-18 23:17:22 +00:00
//
this.imageBox2.BackColor = System.Drawing.Color.Transparent;
this.imageBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.imageBox2.ErrorImage = null;
this.imageBox2.Image = global::AppLauncher.Resource1.maximise_20;
2020-05-18 00:37:54 +00:00
this.imageBox2.ImageHover = global::AppLauncher.Resource1.maximise_20;
this.imageBox2.ImageNormal = global::AppLauncher.Resource1.maximise_20;
this.imageBox2.ImageSelected = global::AppLauncher.Resource1.maximise2_20;
this.imageBox2.InitialImage = null;
this.imageBox2.IsSelected = false;
this.imageBox2.Location = new System.Drawing.Point(139, 12);
this.imageBox2.Name = "imageBox2";
this.imageBox2.Size = new System.Drawing.Size(20, 20);
this.imageBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.imageBox2.TabIndex = 147;
this.imageBox2.TabStop = false;
this.imageBox2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.imageBox2_MouseClick);
2020-05-18 23:17:22 +00:00
//
// imageBox1
2020-05-18 23:17:22 +00:00
//
this.imageBox1.BackColor = System.Drawing.Color.Transparent;
this.imageBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.imageBox1.ErrorImage = null;
this.imageBox1.Image = global::AppLauncher.Resource1.minimise_20;
this.imageBox1.ImageHover = global::AppLauncher.Resource1.minimise2_20;
this.imageBox1.ImageNormal = global::AppLauncher.Resource1.minimise_20;
this.imageBox1.ImageSelected = null;
this.imageBox1.InitialImage = null;
this.imageBox1.IsSelected = false;
this.imageBox1.Location = new System.Drawing.Point(109, 12);
this.imageBox1.Name = "imageBox1";
this.imageBox1.Size = new System.Drawing.Size(20, 20);
this.imageBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.imageBox1.TabIndex = 148;
this.imageBox1.TabStop = false;
this.imageBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.imageBox1_MouseClick);
2020-05-18 23:17:22 +00:00
//
// notifyIcon1
2020-05-18 23:17:22 +00:00
//
2020-05-18 19:45:25 +00:00
this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
2020-05-18 19:45:25 +00:00
this.notifyIcon1.Visible = true;
this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);
this.notifyIcon1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick);
2020-05-18 23:17:22 +00:00
//
2020-05-18 19:45:25 +00:00
// contextMenuStrip1
2020-05-18 23:17:22 +00:00
//
2020-05-18 19:45:25 +00:00
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.exitToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(94, 26);
2020-05-18 23:17:22 +00:00
//
2020-05-18 19:45:25 +00:00
// exitToolStripMenuItem
2020-05-18 23:17:22 +00:00
//
2020-05-18 19:45:25 +00:00
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(93, 22);
this.exitToolStripMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
2020-05-18 23:17:22 +00:00
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Transparent;
this.panel1.Cursor = System.Windows.Forms.Cursors.SizeNS;
this.panel1.Location = new System.Drawing.Point(109, 114);
this.panel1.Margin = new System.Windows.Forms.Padding(0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 2);
this.panel1.TabIndex = 149;
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
//
2020-05-17 03:31:25 +00:00
// AForm
2020-05-18 23:17:22 +00:00
//
2020-05-17 03:31:25 +00:00
this.ClientSize = new System.Drawing.Size(421, 321);
this.Controls.Add(this.panel1);
this.Controls.Add(this.imageBox1);
this.Controls.Add(this.imageBox2);
2020-05-17 03:31:25 +00:00
this.Controls.Add(this.imageBox3);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "AForm";
((System.ComponentModel.ISupportInitialize)(this.imageBox3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.imageBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.imageBox1)).EndInit();
2020-05-18 19:45:25 +00:00
this.contextMenuStrip1.ResumeLayout(false);
2020-05-17 03:31:25 +00:00
this.ResumeLayout(false);
}
private void imageBox1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//this.WindowState = FormWindowState.Minimized;
this.Visible = false;
2020-05-18 19:45:25 +00:00
//notifyIcon1.Visible = true;
}
}
private void imageBox2_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
2020-05-18 00:37:54 +00:00
//this.WindowState = ((this.WindowState == FormWindowState.Maximized) ? FormWindowState.Normal : FormWindowState.Maximized);
2020-05-18 00:37:54 +00:00
//imageBox2.IsSelected = (this.WindowState == FormWindowState.Maximized);
}
else if (e.Button == MouseButtons.Right)
{
this.TopMost = !this.TopMost;
2020-10-20 21:42:40 +00:00
if (this.TopMost)
{
imageBox2.Image = imageBox2.ImageNormal = Resource1.maximise3_20;
}
else
{
imageBox2.Image = imageBox2.ImageNormal = Resource1.maximise_20;
}
}
}
2020-05-20 00:42:51 +00:00
protected virtual void imageBox3_MouseClick(object sender, MouseEventArgs e)
2020-05-17 03:31:25 +00:00
{
if (e.Button == MouseButtons.Left)
{
this.Close();
}
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDragging = true;
startPosition = e.Location;
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
this.Size = new Size(this.Width, e.Y - startPosition.Y + this.Height);
}
}
2020-05-18 19:45:25 +00:00
private void exitToolStripMenuItem_Click(object sender, EventArgs e) => this.Close();
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Visible = !this.Visible;
}
//notifyIcon1.Visible = !this.Visible;
}
2020-03-28 02:54:08 +00:00
}
2020-05-10 10:03:55 +00:00
}