namespace RyzStudio.Windows.ThemedForms
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
///
/// Theme customised form
///
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;
///
/// Initializes a new instance of the Form class
///
public Form()
{
this.InitializeComponent();
this.BackColor = Color.FromArgb(246, 246, 246);
}
///
/// Onresize event
///
/// Event argument
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Invalidate();
}
///
/// OnPaint event
///
/// Event argument
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;
}
}
}