#region Imports
|
|
using DPumpHydr.WinFrmUI.RLT.Enum.Metro;
|
using DPumpHydr.WinFrmUI.RLT.Extension.Metro;
|
using DPumpHydr.WinFrmUI.RLT.Interface.Metro;
|
using DPumpHydr.WinFrmUI.RLT.Manager;
|
using System;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Runtime.InteropServices;
|
using System.Windows.Forms;
|
|
#endregion
|
|
namespace DPumpHydr.WinFrmUI.RLT.Controls
|
{
|
#region MetroPanel
|
|
[ToolboxItem(true)]
|
[ToolboxBitmap(typeof(MetroPanel), "Bitmaps.Panel.bmp")]
|
[ComVisible(true)]
|
public class MetroPanel : System.Windows.Forms.Panel, IMetroControl
|
{
|
#region Interfaces
|
|
[Category("Metro"), Description("Gets or sets the style associated with the control.")]
|
public Style Style
|
{
|
get => StyleManager?.Style ?? _style;
|
set
|
{
|
_style = value;
|
switch (value)
|
{
|
case Style.Light:
|
ApplyTheme();
|
break;
|
case Style.Dark:
|
ApplyTheme(Style.Dark);
|
break;
|
case Style.Custom:
|
ApplyTheme(Style.Custom);
|
break;
|
default:
|
ApplyTheme();
|
break;
|
}
|
Invalidate();
|
}
|
}
|
|
[Category("Metro"), Description("Gets or sets the Style Manager associated with the control.")]
|
public MetroStyleManager StyleManager
|
{
|
get => _styleManager;
|
set { _styleManager = value; Invalidate(); }
|
}
|
|
[Category("Metro"), Description("Gets or sets the The Author name associated with the theme.")]
|
public string ThemeAuthor { get; set; }
|
|
[Category("Metro"), Description("Gets or sets the The Theme name associated with the theme.")]
|
public string ThemeName { get; set; }
|
|
#endregion Interfaces
|
|
#region Global Vars
|
|
private readonly Utilites _utl;
|
|
#endregion Global Vars
|
|
#region Internal Vars
|
|
private Style _style;
|
private MetroStyleManager _styleManager;
|
|
private bool _isDerivedStyle = true;
|
private int _borderThickness = 1;
|
private Color _borderColor;
|
private Color _backgroundColor;
|
|
#endregion Internal Vars
|
|
#region Constructors
|
|
public MetroPanel()
|
{
|
SetStyle
|
(
|
ControlStyles.UserPaint |
|
ControlStyles.AllPaintingInWmPaint |
|
ControlStyles.ResizeRedraw |
|
ControlStyles.OptimizedDoubleBuffer |
|
ControlStyles.SupportsTransparentBackColor,
|
true
|
);
|
BorderStyle = BorderStyle.None;
|
UpdateStyles();
|
_utl = new Utilites();
|
ApplyTheme();
|
}
|
|
#endregion Constructors
|
|
#region ApplyTheme
|
|
private void ApplyTheme(Style style = Style.Light)
|
{
|
if (!IsDerivedStyle)
|
{
|
return;
|
}
|
|
switch (style)
|
{
|
case Style.Light:
|
BorderColor = Color.FromArgb(150, 150, 150);
|
BackgroundColor = Color.White;
|
ThemeAuthor = "Taiizor";
|
ThemeName = "MetroLight";
|
UpdateProperties();
|
break;
|
case Style.Dark:
|
BorderColor = Color.FromArgb(110, 110, 110);
|
BackgroundColor = Color.FromArgb(30, 30, 30);
|
ThemeAuthor = "Taiizor";
|
ThemeName = "MetroDark";
|
UpdateProperties();
|
break;
|
case Style.Custom:
|
if (StyleManager != null)
|
{
|
foreach (System.Collections.Generic.KeyValuePair<string, object> varkey in StyleManager.LabelDictionary)
|
{
|
switch (varkey.Key)
|
{
|
case "BorderColor":
|
BorderColor = _utl.HexColor((string)varkey.Value);
|
break;
|
case "BackColor":
|
BackgroundColor = _utl.HexColor((string)varkey.Value);
|
break;
|
default:
|
return;
|
}
|
}
|
}
|
|
UpdateProperties();
|
break;
|
default:
|
throw new ArgumentOutOfRangeException(nameof(style), style, null);
|
}
|
}
|
|
private void UpdateProperties()
|
{
|
Invalidate();
|
}
|
|
#endregion Theme Changing
|
|
#region Draw Control
|
|
protected override void OnPaint(PaintEventArgs e)
|
{
|
Graphics g = e.Graphics;
|
Rectangle r = new(BorderThickness, BorderThickness, Width - ((BorderThickness * 2) + 1), Height - ((BorderThickness * 2) + 1));
|
|
using SolidBrush bg = new(BackgroundColor);
|
using Pen p = new(BorderColor, BorderThickness);
|
g.FillRectangle(bg, r);
|
g.DrawRectangle(p, r);
|
|
}
|
|
#endregion
|
|
#region Properties
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
public override Color BackColor => Color.Transparent;
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
public override Color ForeColor => Color.Transparent;
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
public new BorderStyle BorderStyle;
|
|
[Category("Metro"), Description("Gets or sets the border thickness the control.")]
|
public int BorderThickness
|
{
|
get => _borderThickness;
|
set
|
{
|
_borderThickness = value;
|
Refresh();
|
}
|
}
|
|
[Category("Metro"), Description("Gets or sets bordercolor used by the control.")]
|
public Color BorderColor
|
{
|
get => _borderColor;
|
set
|
{
|
_borderColor = value;
|
Refresh();
|
}
|
}
|
|
[Category("Metro"), Description("Gets or sets backcolor used by the control.")]
|
[DisplayName("BackColor")]
|
public Color BackgroundColor
|
{
|
get => _backgroundColor;
|
set
|
{
|
_backgroundColor = value;
|
Refresh();
|
}
|
}
|
|
[Category("Metro")]
|
[Description("Gets or sets the whether this control reflect to parent(s) style. \n " +
|
"Set it to false if you want the style of this control be independent. ")]
|
public bool IsDerivedStyle
|
{
|
get => _isDerivedStyle;
|
set
|
{
|
_isDerivedStyle = value;
|
Refresh();
|
}
|
}
|
|
#endregion
|
}
|
|
#endregion
|
}
|