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/RyzStudio/Windows/ThemedForms/TDialogForm.cs

130 lines
4.0 KiB
C#
Raw Normal View History

2020-04-27 12:17:13 +00:00
namespace RyzStudio.Windows.ThemedForms
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using Resources = AppLauncher.Properties.Resources;
2020-05-10 10:45:54 +00:00
public partial class TDialogForm : System.Windows.Forms.Form
2020-04-27 12:17:13 +00:00
{
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(152, 175, 206);
protected readonly Color titleBarForeColour = Color.White;
protected readonly Font titleBarFont = new Font("Segoe UI", 8.25F, FontStyle.Bold, GraphicsUnit.Point, 0);
protected readonly int titleBarHeight = 32;
2020-04-27 12:17:13 +00:00
2020-05-17 02:24:46 +00:00
private bool isDragging = false;
private Point startPosition = new Point();
2020-04-27 12:17:13 +00:00
2020-05-17 02:24:46 +00:00
protected bool isBusy = false;
2020-04-27 12:17:13 +00:00
2020-05-10 10:45:54 +00:00
public TDialogForm() : base()
2020-04-27 12:17:13 +00:00
{
this.InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
2020-05-17 02:24:46 +00:00
this.ShowInTaskbar = false;
2020-04-27 12:17:13 +00:00
imgbxClose.Click += pictureBox3_Click;
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
if (this.IsBusy)
{
e.Cancel = true;
}
}
2020-05-17 02:24:46 +00:00
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
isDragging = true;
startPosition = e.Location;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
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 = new Point(x, y);
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
isDragging = false;
}
2020-04-27 12:17:13 +00:00
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
2020-05-17 02:24:46 +00:00
Rectangle area = new Rectangle(this.DisplayRectangle.X, this.DisplayRectangle.Y, (this.DisplayRectangle.Width - borderWidth), (this.DisplayRectangle.Height - borderWidth));
2020-04-27 12:17:13 +00:00
2020-05-17 02:24:46 +00:00
// border
g.DrawRectangle(new Pen(borderColour, borderWidth), area);
2020-04-27 12:17:13 +00:00
2020-05-17 02:24:46 +00:00
area.Inflate((-1 * borderWidth), (-1 * borderWidth));
g.FillRectangle(new SolidBrush(titleBarColour), area.X, area.Y, (area.Width + area.X), titleBarHeight);
TextRenderer.DrawText(g, this.Title, titleBarFont, new Point(12, 11), titleBarForeColour);
2020-04-27 12:17:13 +00:00
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Invalidate();
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
2020-05-17 02:24:46 +00:00
public override Color BackColor { get => base.BackColor; set => base.BackColor = Color.FromArgb(254, 254, 254); }
2020-04-27 12:17:13 +00:00
[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 = value; }
[Category("Appearance"), Browsable(true)]
2020-05-17 02:24:46 +00:00
public string Title { get; set; }
2020-04-27 12:17:13 +00:00
protected virtual bool IsBusy { get => isBusy; set => isBusy = value; }
private void pictureBox3_Click(object sender, System.EventArgs e)
{
MouseEventArgs mouseEvent = (MouseEventArgs)e;
if (mouseEvent != null)
{
if (mouseEvent.Button != MouseButtons.Left)
{
return;
}
}
this.Close();
}
}
}