mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-02 07:09:27 +03:00
Added DarkLabel
This commit is contained in:
parent
7e94c286d7
commit
4d5bf78403
92
DarkUI/Controls/DarkLabel.cs
Normal file
92
DarkUI/Controls/DarkLabel.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace DarkUI
|
||||||
|
{
|
||||||
|
public class DarkLabel : Label
|
||||||
|
{
|
||||||
|
#region Field Region
|
||||||
|
|
||||||
|
private bool _autoUpdateHeight;
|
||||||
|
private bool _isGrowing;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Property Region
|
||||||
|
|
||||||
|
[Category("Appearance")]
|
||||||
|
[Description("Determines whether the label will automatically update height based on content.")]
|
||||||
|
[DefaultValue(false)]
|
||||||
|
public bool AutoUpdateHeight
|
||||||
|
{
|
||||||
|
get { return _autoUpdateHeight; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_autoUpdateHeight = value;
|
||||||
|
|
||||||
|
if (_autoUpdateHeight)
|
||||||
|
{
|
||||||
|
AutoSize = false;
|
||||||
|
ResizeLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructor Region
|
||||||
|
|
||||||
|
public DarkLabel()
|
||||||
|
{
|
||||||
|
ForeColor = Colors.LightText;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Method Region
|
||||||
|
|
||||||
|
private void ResizeLabel()
|
||||||
|
{
|
||||||
|
if (!_autoUpdateHeight || _isGrowing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_isGrowing = true;
|
||||||
|
var sz = new Size(Width, int.MaxValue);
|
||||||
|
sz = TextRenderer.MeasureText(Text, Font, sz, TextFormatFlags.WordBreak);
|
||||||
|
Height = sz.Height + Padding.Vertical;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isGrowing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Event Handler Region
|
||||||
|
|
||||||
|
protected override void OnTextChanged(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnTextChanged(e);
|
||||||
|
ResizeLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFontChanged(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnFontChanged(e);
|
||||||
|
ResizeLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnSizeChanged(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnSizeChanged(e);
|
||||||
|
ResizeLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -43,6 +43,9 @@
|
|||||||
<Compile Include="Controls\DarkButton.cs">
|
<Compile Include="Controls\DarkButton.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Controls\DarkLabel.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Controls\DarkMenuStrip.cs">
|
<Compile Include="Controls\DarkMenuStrip.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user