AdvancedLabel Class

Represents a label with additional features such as customizable disabled colors, correct auto sizing, fixed auto sizing behavior, advanced border styles, and more.

See the online help for an image example.

Definition

Namespace: KGySoft.WinForms.Controls
Assembly: KGySoft.WinForms (in KGySoft.WinForms.dll) Version: 5.0.1
C#
[ToolboxBitmapAttribute(typeof(AdvancedLabel), "Resources.Toolbox.AdvancedLabel.png")]
public class AdvancedLabel : LinkLabel, 
	ISupportsFading<ControlAppearanceState>, IWin32Window
Inheritance
Object    MarshalByRefObject    Component    Control    Label    LinkLabel    AdvancedLabel
Implements
ISupportsFadingControlAppearanceState, IWin32Window

Remarks

The AdvancedLabel class offers the following features in addition to LinkLabel:
  • The AutoSize property works as expected when the label is docked.
  • Different rendering qualities (see TextRenderingQuality).
  • Advanced border styles.
  • Adjustable colors in disabled state (see DisabledBackColor and DisabledForeColor).
  • Buffered fading animations (only on Vista and above with visual styles enabled, see FadingAnimationsEnabled and FadingAnimationOptions).
  • Automatic resolve of hyperlinks.
  • Consistent font scaling on all platforms when per-monitor DPI awareness is enabled (see AutoScaleFont). Note that it affects font scaling only, so auto-sizing behavior still depends on the current platform.
  • Fixing some Mono-specific Label/LinkLabel issues, such as non-visible text with border, wrong rendering with padding, random exceptions from mouse events when links are used.

Examples

The following image illustrates a few features of the AdvancedLabel class, like as the various BorderStyle options, the default disabled colors difference, and the fixed auto sizing behavior when the control is docked to the top:

AdvancedLabel in the KGySoft.WinForms.Example application

  Tip

The image above is from the example application. At the Releases page of the project repository you can download it as executable binaries as well.

Constructors

AdvancedLabel Creates a new instance of AdvancedLabel.

Properties

AutoHandleUrls Gets or sets whether clicked links should be handled automatically or when Handled is set to .
Default value: .
AutoScaleFont Gets or sets whether the Font should be automatically scaled when DPI changes and the current thread has per-monitor DPI awareness.
Default value: .
BackColor Gets or sets the background color of the control in the current Enabled state.
(Overrides ControlBackColor)
BorderStyle Gets or sets the border style of the AdvancedLabel.

See the online help for an image example.
DisabledBackColor Gets or sets the background color when the control is not Enabled.
DisabledForeColor Gets or sets the text color when the control is not Enabled.
EnabledBackColor Gets or sets the background color when the control is Enabled.
EnabledForeColor Gets or sets the text color when the control is Enabled.
FadingAnimationDefaultSpeed Gets or sets the default fading animation speed for non-standard animations in milliseconds. Zero value means immediate change.
Default value: 500.
FadingAnimationOptions Gets or sets the fading options of the control.
Default value: StandardEffects. In case of an AdvancedLabel, it covers the animation of the enabled/disabled transition.
FadingAnimationsEnabled Gets or sets whether fading animations are enabled for the control. Animations work on Windows Vista and above when rendering with visual styles.
Default value: .
FontGets or sets the font of the text displayed by the control.
(Overrides ControlFont)
ForeColor Gets or sets the foreground color of the control in the current Enabled state.
(Overrides ControlForeColor)
LinkAreaGets or sets the range in the text to treat as a link.
RawText Gets or sets the raw text of the label. When ResolveHyperlinks is not None, the value of this property may differ from Text.
ResolveHyperlinks Gets or sets whether hyperlinks should be resolved.
Text Gets or sets text of the label. When ResolveHyperlinks is not None, hyperlinks in text will be converted to links automatically.
(Overrides LinkLabelText)
TextRenderingQuality Gets or sets the text rendering quality of the AdvancedLabel.
Default value: SystemDefault.

See the online help of the AdvancedRadioButton class for an image example.
UseCompatibleTextRendering Gets or sets whether to use the text rendering engine compatible with .NET Framework 1.x (GDI+) or not (GDI).
Default value: .

Methods

DisposeReleases the unmanaged resources used by the AdvancedLabel and optionally releases the managed resources
(Overrides LinkLabelDispose(Boolean))
GetPreferredSizeRetrieves the size of a rectangular area into which a control can be fitted.
(Overrides LabelGetPreferredSize(Size))
OnBackColorChangedRaises the BackColorChanged event.
(Overrides ControlOnBackColorChanged(EventArgs))
OnEnabledChangedProvides handling for the EnabledChanged event.
(Overrides LinkLabelOnEnabledChanged(EventArgs))
OnFontChangedRaises the FontChanged event.
(Overrides LinkLabelOnFontChanged(EventArgs))
OnForeColorChangedRaises the ForeColorChanged event.
(Overrides ControlOnForeColorChanged(EventArgs))
OnHandleCreatedRaises the HandleCreated event.
(Overrides ControlOnHandleCreated(EventArgs))
OnHyperlinkClicked Raises the HyperlinkClicked event.
OnMouseDownRaises the MouseDown event.
(Overrides LinkLabelOnMouseDown(MouseEventArgs))
OnMouseMoveRaises the MouseMove event.
(Overrides LinkLabelOnMouseMove(MouseEventArgs))
OnMouseUpRaises the MouseUp event.
(Overrides LinkLabelOnMouseUp(MouseEventArgs))
OnPaddingChangedRaises the PaddingChanged event.
(Overrides LinkLabelOnPaddingChanged(EventArgs))
OnPaint Implicitly calls the OnPaintState method, which raises both the Paint and PaintState events.
(Overrides LinkLabelOnPaint(PaintEventArgs))
OnPaintState Paints the specified state of this control, and raises the PaintState event.
OnParentChangedRaises the ParentChanged event.
(Overrides LabelOnParentChanged(EventArgs))
OnParentFontChangedRaises the FontChanged event when the Font property value of the control's container changes.
(Overrides ControlOnParentFontChanged(EventArgs))
OnSizeChangedRaises the SizeChanged event.
(Overrides ControlOnSizeChanged(EventArgs))
OnVisibleChangedRaises the VisibleChanged event.
(Overrides LabelOnVisibleChanged(EventArgs))
WndProcProcesses Windows messages.
(Overrides LinkLabelWndProc(Message))

Events

HyperlinkClicked Occurs when a link is clicked. To handle clicked links automatically, set the AutoHandleUrls property to . If this event is subscribed, you can also set Handled to to navigate to the target site automatically.
PaintState Occurs when the control is painted in a specific state.

Extension Methods

GetFormatFlags Gets the formatting flags for the text of a custom drawn control.
(Defined by ControlExtensions)
GetScale Gets the current scale factor of the specified control. If per-monitor DPI awareness is not enabled, it always returns SystemScale.
(Defined by ScaleHelper)
GetScrollBarSize Gets the recommended width and height of scrollbars matching the current scaling of the specified control.
(Defined by ScaleHelper)
HasDefaultScaling Gets whether the display that the specified control belongs to has the same DPI as the initial DPI of the primary display.
(Defined by ScaleHelper)
ScaleHeight Scales the specified height by the vertical scale factor of the control.
(Defined by ScaleHelper)
ScaleSize Scales the specified size by the scale factor of the control.
(Defined by ScaleHelper)
ScaleWidth Scales the specified width by the horizontal scale factor of the control.
(Defined by ScaleHelper)
SetControlEnabled Sets the Enabled property of the child controls within the specified root control, or the Enabled property of the specified control itself, if it is not a recognized container control. By this way pages of a TabControl will remain selectable, a SplitContainer remains resizable, etc.
(Defined by ControlExtensions)
SetControlReadonly Recursively sets the read-only state in the children of the specified root control. Affects TextBoxBase and IReadOnlyCapable instances.
(Defined by ControlExtensions)
SetDoubleBuffered Sets the double buffered state of a control
(Defined by ControlExtensions)
SetStyle Sets a specified ControlStyles flag to either or . It calls the protected Control.SetStyle method on the specified control as if it was a public method.
(Defined by ControlExtensions)

See Also