138 lines
4.6 KiB
C#
138 lines
4.6 KiB
C#
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();
|
|
|
|
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;
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
if (this.DesignMode)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//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);
|
|
|
|
//this.Location = newPosition;
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
//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);
|
|
//}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |