186 lines
4.1 KiB
C#
186 lines
4.1 KiB
C#
|
namespace RyzStudio.Windows.ThemedForms
|
|||
|
{
|
|||
|
using System;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Drawing;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Theme customised form
|
|||
|
/// </summary>
|
|||
|
public partial class Form : System.Windows.Forms.Form
|
|||
|
{
|
|||
|
protected Image topImage = null;
|
|||
|
protected Color topFillColour = Color.FromArgb(15, 15, 15);
|
|||
|
protected int topFillHeight = 52;
|
|||
|
|
|||
|
protected Image bottomImage = null;
|
|||
|
protected Color bottomFillColour = Color.FromArgb(15, 15, 15);
|
|||
|
protected int bottomFillMargin = 19;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Initializes a new instance of the Form class
|
|||
|
/// </summary>
|
|||
|
public Form()
|
|||
|
{
|
|||
|
this.InitializeComponent();
|
|||
|
|
|||
|
this.BackColor = Color.FromArgb(246, 246, 246);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Onresize event
|
|||
|
/// </summary>
|
|||
|
/// <param name="e">Event argument</param>
|
|||
|
protected override void OnResize(EventArgs e)
|
|||
|
{
|
|||
|
base.OnResize(e);
|
|||
|
|
|||
|
this.Invalidate();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// OnPaint event
|
|||
|
/// </summary>
|
|||
|
/// <param name="e">Event argument</param>
|
|||
|
protected override void OnPaint(PaintEventArgs e)
|
|||
|
{
|
|||
|
base.OnPaint(e);
|
|||
|
|
|||
|
Graphics g = e.Graphics;
|
|||
|
|
|||
|
Rectangle areaTop = new Rectangle(this.DisplayRectangle.Left, 0, this.DisplayRectangle.Width, topFillHeight);
|
|||
|
Rectangle areaBottom = new Rectangle(this.DisplayRectangle.Left, (this.DisplayRectangle.Height - bottomFillMargin), this.DisplayRectangle.Width, bottomFillMargin);
|
|||
|
|
|||
|
// 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 (topImage != null)
|
|||
|
{
|
|||
|
g.DrawImageUnscaled(topImage, 0, 0);
|
|||
|
}
|
|||
|
|
|||
|
if (bottomImage != null)
|
|||
|
{
|
|||
|
g.DrawImageUnscaled(bottomImage, 0, (this.DisplayRectangle.Height - bottomImage.Height - bottomFillMargin), this.DisplayRectangle.Width, bottomImage.Height);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region public properties
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region public properties (encapsulation)
|
|||
|
|
|||
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
|||
|
public new Color BackColor { get { return base.BackColor; } set { base.BackColor = value; } }
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|