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/Form.cs
2020-04-27 13:17:13 +01:00

173 lines
4.1 KiB
C#

namespace RyzStudio.Windows.ThemedForms
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public partial class Form : System.Windows.Forms.Form
{
protected Color topFillColour = Color.FromArgb(15, 15, 15);
protected int topFillHeight = 52;
protected Color bottomFillColour = Color.FromArgb(15, 15, 15);
protected int bottomFillMargin = 19;
protected int borderWidth = 1;
public Form()
{
this.InitializeComponent();
this.BackColor = Color.FromArgb(246, 246, 246);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
Rectangle areaTop = new Rectangle(this.DisplayRectangle.Left, this.Padding.Top, this.DisplayRectangle.Width, topFillHeight);
Rectangle areaBottom = new Rectangle(this.DisplayRectangle.Left, (this.DisplayRectangle.Height - bottomFillMargin), this.DisplayRectangle.Width, bottomFillMargin);
Rectangle areaBorder = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - borderWidth, this.ClientRectangle.Height - borderWidth);
// draw header
if (topFillHeight > 0)
{
g.FillRectangle(new SolidBrush(topFillColour), areaTop);
}
// draw footer
if (bottomFillMargin > 0)
{
g.FillRectangle(new SolidBrush(bottomFillColour), areaBottom);
}
// draw logo
if (this.TitleLogo != null)
{
g.DrawImageUnscaled(this.TitleLogo, this.Padding.Left, this.Padding.Top);
}
if (this.Banner != null)
{
g.DrawImageUnscaled(this.Banner, this.Padding.Left, (this.DisplayRectangle.Height - this.Banner.Height - bottomFillMargin), (this.DisplayRectangle.Width - (this.Padding.Left + this.Padding.Right)), this.Banner.Height);
}
g.DrawRectangle(new Pen(Color.Black, borderWidth), areaBorder);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Color BackColor { get => base.BackColor; set { base.BackColor = value; } }
[Category("Appearance"), Browsable(true)]
public Image TitleLogo { get; set; }
[Category("Appearance"), Browsable(true)]
public Image Banner { get; set; }
public void SetValue(Label sender, string value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Text = value; }));
}
else
{
sender.Text = value;
}
}
public void SetValue(GroupBox sender, string value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Text = value; }));
}
else
{
sender.Text = value;
}
}
public void AddValue(ListBox sender, string value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Items.Add(value); }));
}
else
{
sender.Items.Add(value);
}
}
public void ClearValues(ListBox sender)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Items.Clear(); }));
}
else
{
sender.Items.Clear();
}
}
public string GetValue(ListBox sender)
{
string rv = string.Empty;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString(); }));
}
else
{
rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString();
}
return rv;
}
public string GetValue(TextBox sender)
{
string rv = string.Empty;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { rv = sender.Text.Trim(); }));
}
else
{
rv = sender.Text.Trim();
}
return rv;
}
public int GetValue(NumericUpDown sender)
{
int rv = 0;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { rv = (int)sender.Value; }));
}
else
{
rv = (int)sender.Value;
}
return rv;
}
}
}