mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-26 12:08:37 +08:00
NBLabel now respects the TextAlignment property when in theming mode
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using mRemoteNG.Themes;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
@@ -13,6 +14,7 @@ namespace mRemoteNG.UI.Controls.Base
|
||||
public class NGLabel : Label
|
||||
{
|
||||
private ThemeManager _themeManager;
|
||||
private TextFormatFlags _textFormatFlags;
|
||||
|
||||
public NGLabel()
|
||||
{
|
||||
@@ -28,9 +30,52 @@ namespace mRemoteNG.UI.Controls.Base
|
||||
BackColor = _themeManager.ActiveTheme.ExtendedPalette.getColor("Dialog_Background");
|
||||
ForeColor = _themeManager.ActiveTheme.ExtendedPalette.getColor("Dialog_Foreground");
|
||||
FontOverrider.FontOverride(this);
|
||||
BuildTextFormatFlags();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void BuildTextFormatFlags()
|
||||
{
|
||||
_textFormatFlags = TextFormatFlags.TextBoxControl;
|
||||
|
||||
// in default labels, wordwrap is enabled when autosize is false
|
||||
if (AutoSize == false)
|
||||
_textFormatFlags |= TextFormatFlags.WordBreak;
|
||||
|
||||
switch (TextAlign)
|
||||
{
|
||||
case ContentAlignment.TopLeft:
|
||||
_textFormatFlags |= TextFormatFlags.Top | TextFormatFlags.Left;
|
||||
break;
|
||||
case ContentAlignment.TopCenter:
|
||||
_textFormatFlags |= TextFormatFlags.Top | TextFormatFlags.HorizontalCenter;
|
||||
break;
|
||||
case ContentAlignment.TopRight:
|
||||
_textFormatFlags |= TextFormatFlags.Top | TextFormatFlags.Right;
|
||||
break;
|
||||
case ContentAlignment.MiddleLeft:
|
||||
_textFormatFlags |= TextFormatFlags.VerticalCenter | TextFormatFlags.Left;
|
||||
break;
|
||||
case ContentAlignment.MiddleCenter:
|
||||
_textFormatFlags |= TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
|
||||
break;
|
||||
case ContentAlignment.MiddleRight:
|
||||
_textFormatFlags |= TextFormatFlags.VerticalCenter | TextFormatFlags.Right;
|
||||
break;
|
||||
case ContentAlignment.BottomLeft:
|
||||
_textFormatFlags |= TextFormatFlags.Bottom | TextFormatFlags.Left;
|
||||
break;
|
||||
case ContentAlignment.BottomCenter:
|
||||
_textFormatFlags |= TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter;
|
||||
break;
|
||||
case ContentAlignment.BottomRight:
|
||||
_textFormatFlags |= TextFormatFlags.Bottom | TextFormatFlags.Right;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (!_themeManager.ThemingActive)
|
||||
@@ -44,14 +89,12 @@ namespace mRemoteNG.UI.Controls.Base
|
||||
//e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||
if (Enabled)
|
||||
{
|
||||
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, ForeColor,
|
||||
TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
|
||||
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, ForeColor, _textFormatFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
var disabledtextLabel = _themeManager.ActiveTheme.ExtendedPalette.getColor("TextBox_Disabled_Foreground");
|
||||
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, disabledtextLabel,
|
||||
TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
|
||||
TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, disabledtextLabel, _textFormatFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user