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; public partial class TDialogForm : System.Windows.Forms.Form { //protected readonly Color borderColour = Color.FromArgb(232, 231, 236); protected readonly Color borderColour = Color.FromArgb(77, 84, 100); 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; private bool isDragging = false; private Point startPosition = new Point(); protected bool isBusy = false; public TDialogForm() : base() { this.InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.ShowInTaskbar = false; this.TopMost = true; imgbxClose.Click += pictureBox3_Click; } protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); if (this.IsBusy) { e.Cancel = true; } } 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; } 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); g.DrawLine(new Pen(borderColour, 1), this.DisplayRectangle.X, (titleBarHeight + 1), this.DisplayRectangle.Width, (titleBarHeight + 1)); 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); } 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 = value; } [Category("Appearance"), Browsable(true)] public string Title { get; set; } 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(); } } }