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

207 lines
7.0 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;
protected readonly Color titleBarColour = Color.FromArgb(237, 240, 247);
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;
2020-05-17 03:31:25 +00:00
protected internal RyzStudio.Windows.Forms.TImageBox imageBox3;
2020-05-17 02:24:46 +00:00
private Point startPosition = new Point();
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-17 03:31:25 +00:00
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.SuspendLayout();
imageBox3.Left = this.DisplayRectangle.Width - imageBox3.Width - 17;
imageBox3.Top = 17;
imageBox3.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
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));
g.DrawImageUnscaled(Properties.Resources.app_icon_24, 17, 17);
TextRenderer.DrawText(g, "Launcher", new Font(this.Font.FontFamily, 14F), new Point(58, 17), Color.FromArgb(156, 158, 171));
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Invalidate();
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override Color BackColor { get => base.BackColor; set => base.BackColor = Color.FromArgb(254, 254, 254); }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new FormBorderStyle FormBorderStyle { get => base.FormBorderStyle; set => base.FormBorderStyle = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Padding Padding { get => base.Padding; set => base.Padding = new Padding(0); }
[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.imageBox3 = new RyzStudio.Windows.Forms.TImageBox();
((System.ComponentModel.ISupportInitialize)(this.imageBox3)).BeginInit();
this.SuspendLayout();
//
// imageBox3
//
this.imageBox3.BackColor = System.Drawing.Color.Transparent;
this.imageBox3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.imageBox3.ErrorImage = null;
this.imageBox3.HighlightImage = global::AppLauncher.Resource1.close2_20;
this.imageBox3.Image = global::AppLauncher.Resource1.close_20;
this.imageBox3.InitialImage = null;
this.imageBox3.Location = new System.Drawing.Point(12, 12);
this.imageBox3.Name = "imageBox3";
this.imageBox3.NormalImage = global::AppLauncher.Resource1.close_20;
this.imageBox3.Size = new System.Drawing.Size(24, 24);
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);
//
// AForm
//
this.ClientSize = new System.Drawing.Size(421, 321);
this.Controls.Add(this.imageBox3);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "AForm";
((System.ComponentModel.ISupportInitialize)(this.imageBox3)).EndInit();
this.ResumeLayout(false);
}
private void imageBox3_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Close();
}
}
2020-03-28 02:54:08 +00:00
}
2020-05-10 10:03:55 +00:00
}