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

106 lines
3.5 KiB
C#
Raw Normal View History

2020-05-10 10:34:45 +00:00
using System;
using System.Drawing;
using System.Windows.Forms;
using RyzStudio.Drawing;
using System.ComponentModel;
2020-04-27 12:17:13 +00:00
2020-05-10 10:34:45 +00:00
namespace RyzStudio.Windows.ThemedForms
{
2020-05-10 10:45:54 +00:00
public partial class TUserControl : System.Windows.Forms.UserControl
2020-04-27 12:17:13 +00:00
{
2020-05-12 23:37:01 +00:00
public class ThemeStyle
2020-05-10 10:34:45 +00:00
{
public int BorderWidth;
public int BorderRadius;
public int BorderPadding;
public Color BorderColour;
public Color BackColour;
public Color ForeColour;
2020-05-12 23:37:01 +00:00
public ThemeStyle(int borderWidth, int borderRadius, int borderPadding, Color borderColour, Color backColour)
2020-05-10 10:34:45 +00:00
{
this.BorderWidth = borderWidth;
this.BorderRadius = borderRadius;
this.BorderPadding = borderPadding;
this.BorderColour = borderColour;
this.BackColour = backColour;
this.ForeColour = Color.Black;
}
2020-05-12 23:37:01 +00:00
public ThemeStyle(int borderWidth, int borderRadius, int borderPadding, Color borderColour, Color backColour, Color foreColour)
2020-05-10 10:34:45 +00:00
{
this.BorderWidth = borderWidth;
this.BorderRadius = borderRadius;
this.BorderPadding = borderPadding;
this.BorderColour = borderColour;
this.BackColour = backColour;
this.ForeColour = foreColour;
}
}
2020-05-12 23:37:01 +00:00
protected ThemeStyle styleActive = new ThemeStyle(1, 3, 2, Color.FromArgb(212, 212, 212), Color.White);
2020-04-27 12:17:13 +00:00
2020-05-10 10:45:54 +00:00
public TUserControl()
2020-04-27 12:17:13 +00:00
{
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;
2020-05-07 22:31:03 +00:00
//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;
2020-04-27 12:17:13 +00:00
2020-05-07 22:31:03 +00:00
updateBackground(g, styleActive);
2020-04-27 12:17:13 +00:00
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Padding Padding { get => base.Padding; set => base.Padding = value; }
2020-05-12 23:37:01 +00:00
protected virtual void updateBackground(Graphics g, ThemeStyle style)
2020-04-27 12:17:13 +00:00
{
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());
}
2020-05-10 10:34:45 +00:00
protected virtual void close()
2020-04-27 12:17:13 +00:00
{
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();
}
}
}
}
}