Files
mRemoteNG/mRemoteV1/UI/Controls/Base/NGLabel.cs
Camilo Alvarez 991d1d82b8 Misc fixes
- Clear redundant settings form app.config
- Deleted DesignModeTest as ThemeManager can now be used in design time without adjustements, removed usage from all custo elements
- Instance _themeManager in NGNumericUpDown at object creation to avoid null reference errors
- Errorsform instancing is now defaulted to DockBottomAutoHide  in frmMain
-Fix missing panel at startup by adding a blank panel, temporary solution as magic library is beign phased out
2017-12-26 12:15:11 -05:00

56 lines
1.7 KiB
C#

using mRemoteNG.Themes;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
namespace mRemoteNG.UI.Controls.Base
{
//Themable label to overide the winforms behavior of drawing the forecolor of disabled with a system color
//This class repaints the control to avoid Disabled state mismatch of the theme
[ToolboxBitmap(typeof(Label))]
public class NGLabel : Label
{
private ThemeManager _themeManager;
public NGLabel()
{
ThemeManager.getInstance().ThemeChanged += OnCreateControl;
}
protected override void OnCreateControl()
{
base.OnCreateControl();
_themeManager = ThemeManager.getInstance();
if (_themeManager.ThemingActive)
{
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (!_themeManager.ThemingActive)
{
base.OnPaint(e);
return;
}
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
if (Enabled)
{
TextRenderer.DrawText(e.Graphics, this.Text, Font, ClientRectangle, ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
}
else
{
var disabledtextLabel = _themeManager.ActiveTheme.ExtendedPalette.getColor("TextBox_Disabled_Foreground");
TextRenderer.DrawText(e.Graphics, this.Text, Font, ClientRectangle, disabledtextLabel, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
}
}
}
}