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

138 lines
4.6 KiB
C#
Raw Normal View History

2020-03-28 02:54:08 +00:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppLauncher.Windows.Forms
{
public class AForm : Form
{
protected bool isDragging = false;
protected Point startPosition = new Point();
2020-03-28 02:54:08 +00:00
public AForm() : base()
{
if (!this.DesignMode)
{
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.Manual;
}
this.MouseDown += mainForm_MouseDown;
this.MouseUp += mainForm_MouseUp;
this.MouseMove += mainForm_MouseMove;
2020-03-28 02:54:08 +00:00
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode)
{
return;
}
2020-05-10 10:03:55 +00:00
//int requestedHeight = (int)Math.Floor(decimal.Divide((Screen.PrimaryScreen.WorkingArea.Height - this.Height), 2));
//this.Location = new Point(Screen.PrimaryScreen.WorkingArea.X, (Screen.PrimaryScreen.WorkingArea.Y + requestedHeight));
//Point newPosition = new Point(Cursor.Position.X, Cursor.Position.Y);
//newPosition.X -= (this.Width / 2);
//newPosition.Y -= (this.Height / 2);
2020-03-28 02:54:08 +00:00
2020-05-10 10:03:55 +00:00
//this.Location = newPosition;
2020-03-28 02:54:08 +00:00
}
protected override void OnPaint(PaintEventArgs e)
2020-03-28 02:54:08 +00:00
{
base.OnPaint(e);
2020-03-28 02:54:08 +00:00
Graphics g = e.Graphics;
Color borderColour = Color.FromArgb(232, 231, 236);
Color menubarColour = Color.FromArgb(237, 240, 247);
Rectangle area = new Rectangle(this.DisplayRectangle.X, this.DisplayRectangle.Y, (this.DisplayRectangle.Width - 1), (this.DisplayRectangle.Height - 1));
// border
g.DrawRectangle(new Pen(borderColour, 1), area);
area.Inflate(-1, -1);
g.FillRectangle(new SolidBrush(menubarColour), area.X, area.Y, (area.Width + area.X), 56);
g.DrawLine(new Pen(borderColour, 1), area.X, 57, (area.Width + area.X), 57);
g.DrawImageUnscaled(Properties.Resources.app_icon_24, 17, 17);
TextRenderer.DrawText(e.Graphics, "Launcher", new Font(this.Font.FontFamily, 14F), new Point(58, 17), Color.FromArgb(156, 158, 171));
//g.DrawRectangle(new Pen(Color.FromArgb(232, 231, 236), 1), borderArea);
//g.DrawRectangle(new Pen(Color.Red, 1), area);
2020-03-28 02:54:08 +00:00
}
//protected override void OnPaintBackground(PaintEventArgs e)
//{
// base.OnPaintBackground(e);
//Graphics g = e.Graphics;
//g.TextRenderingHint = TextRenderingHint.AntiAlias;
//g.InterpolationMode = InterpolationMode.HighQualityBilinear;
//g.PixelOffsetMode = PixelOffsetMode.HighQuality;
//g.SmoothingMode = SmoothingMode.HighQuality;
//g.FillRectangle(new LinearGradientBrush(this.DisplayRectangle, Color.FromArgb(76, 83, 93), Color.FromArgb(255, 255, 255), -30F), this.DisplayRectangle);
//g.DrawRectangle(new Pen(new SolidBrush(Color.Red), 1), this.DisplayRectangle);
//}
2020-05-10 10:03:55 +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);
2020-03-28 02:54:08 +00:00
2020-05-10 10:03:55 +00:00
newPosition.X = Math.Max(newPosition.X, Screen.PrimaryScreen.WorkingArea.Left);
newPosition.Y = Math.Max(newPosition.Y, Screen.PrimaryScreen.WorkingArea.Top);
2020-03-28 02:54:08 +00:00
2020-05-10 10:03:55 +00:00
return newPosition;
}
}
2020-03-28 02:54:08 +00:00
public override Color BackColor { get => base.BackColor; set => base.BackColor = Color.FromArgb(254, 254, 254); }
private void mainForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
isDragging = true;
startPosition = e.Location;
}
private void mainForm_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
private void mainForm_MouseMove(object sender, MouseEventArgs 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-03-28 02:54:08 +00:00
}
2020-05-10 10:03:55 +00:00
}