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/TForm.cs

173 lines
4.1 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.Windows.Forms;
2020-05-10 10:45:54 +00:00
public partial class TForm : System.Windows.Forms.Form
2020-04-27 12:17:13 +00:00
{
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;
2020-05-10 10:45:54 +00:00
public TForm()
2020-04-27 12:17:13 +00:00
{
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;
}
2020-05-10 10:45:54 +00:00
public string GetValue(TTextBox sender)
2020-04-27 12:17:13 +00:00
{
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;
}
}
}