118 lines
3.8 KiB
C#
118 lines
3.8 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using RyzStudio.Drawing;
|
|
using System.ComponentModel;
|
|
|
|
namespace RyzStudio.Windows.ThemedForms
|
|
{
|
|
public partial class UserControl : System.Windows.Forms.UserControl
|
|
{
|
|
public class Style
|
|
{
|
|
public int BorderWidth;
|
|
public int BorderRadius;
|
|
public int BorderPadding;
|
|
public Color BorderColour;
|
|
public Color BackColour;
|
|
public Color ForeColour;
|
|
|
|
public Style(int borderWidth, int borderRadius, int borderPadding, Color borderColour, Color backColour)
|
|
{
|
|
this.BorderWidth = borderWidth;
|
|
this.BorderRadius = borderRadius;
|
|
this.BorderPadding = borderPadding;
|
|
this.BorderColour = borderColour;
|
|
this.BackColour = backColour;
|
|
this.ForeColour = Color.Black;
|
|
}
|
|
|
|
public Style(int borderWidth, int borderRadius, int borderPadding, Color borderColour, Color backColour, Color foreColour)
|
|
{
|
|
this.BorderWidth = borderWidth;
|
|
this.BorderRadius = borderRadius;
|
|
this.BorderPadding = borderPadding;
|
|
this.BorderColour = borderColour;
|
|
this.BackColour = backColour;
|
|
this.ForeColour = foreColour;
|
|
}
|
|
}
|
|
|
|
protected Style styleActive = new Style(1, 3, 2, Color.FromArgb(212, 212, 212), Color.White);
|
|
|
|
public UserControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
this.BackColor = Color.Transparent;
|
|
}
|
|
|
|
protected override void OnPaintBackground(PaintEventArgs e)
|
|
{
|
|
base.OnPaintBackground(e);
|
|
|
|
Graphics g = e.Graphics;
|
|
//g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
//g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
//g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
|
|
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
|
|
|
updateBackground(g, styleActive);
|
|
}
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
|
public new Padding Padding { get => base.Padding; set => base.Padding = value; }
|
|
|
|
protected virtual void updateBackground(Graphics g, Style style)
|
|
{
|
|
int b = (styleActive.BorderWidth + 1) + styleActive.BorderPadding;
|
|
|
|
this.Padding = new Padding(b, b, (b - 1), (b - 1));
|
|
|
|
Rectangoid area = new Rectangoid(this.ClientRectangle, style.BorderRadius, style.BorderWidth);
|
|
g.FillPath(new SolidBrush(style.BackColour), area.ToGraphicsPath());
|
|
g.DrawPath(new Pen(new SolidBrush(style.BorderColour), style.BorderWidth), area.ToGraphicsPath());
|
|
}
|
|
|
|
protected virtual void close()
|
|
{
|
|
if (this.Parent == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.Parent is Form)
|
|
{
|
|
(this.Parent as Form).Close();
|
|
return;
|
|
}
|
|
|
|
if (this.Parent.GetType().IsSubclassOf(typeof(System.Windows.Forms.Form)))
|
|
{
|
|
System.Windows.Forms.Form parentForm = (System.Windows.Forms.Form)this.Parent;
|
|
if (parentForm != null)
|
|
{
|
|
parentForm.Close();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetValue(Label sender, string value)
|
|
{
|
|
if (sender.InvokeRequired)
|
|
{
|
|
sender.Invoke(new MethodInvoker(() => { sender.Text = value; }));
|
|
}
|
|
else
|
|
{
|
|
sender.Text = value;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |