๐Ÿ”น Kt-Label

Overview

KtLabel is an enhanced label control from the KimTools.WinForms SDK that extends the standard Windows Forms Label with theme-aware color management. This control automatically adapts to light/dark theme changes and provides a simplified, theme-integrated approach to text display in modern Windows Forms applications.

Key Features

  • Automatic Theme Integration: Responds to system theme changes in real-time

  • Simplified Color Management: Uses KtColor for consistent theming across your application

  • Transparent Background: Automatically sets transparent background for seamless UI integration

  • Parent Color Inheritance: Inherits parent control colors when no explicit color is set

Use Cases

  • Display static or dynamic text with automatic theme adaptation

  • Create labels that match your application's color scheme automatically

  • Build accessible UI elements that respond to system dark/light mode changes

  • Simplify color management in complex forms with hierarchical color inheritance


Properties

Property
Type
Default
Description

Text

string

""

The text content displayed by the label. Localizable and bindable to settings.

Color

KtColor

KtColor.Empty

The theme-aware color for the label text. Uses KtColor enumeration for automatic theme adaptation. Values are constrained to 0-99 range.

Property Details

Color Property

  • Accepts KtColor enumeration values (constrained via modulo 100 operation)

  • When set to KtColor.Empty, inherits color from parent control

  • Automatically updates when system theme changes

  • See KtColor Documentation for available color values


Events

Note: Standard Label events remain available (Click, TextChanged, etc.)


Essential Features

1. Theme-Aware Rendering

KtLabel automatically subscribes to theme change events and updates its appearance accordingly:

When the system switches between light and dark modes, all KtLabel instances update their colors automatically without requiring code intervention.

2. Intelligent Color Inheritance

The control implements a smart color resolution system:

  1. If Color is set to a specific KtColor value, use that color

  2. If Color is KtColor.Empty, inherit from parent control's ForeColor

  3. Fallback to current ForeColor if no parent is available

3. Transparent Integration

The label automatically sets its background to transparent, ensuring seamless integration with parent containers:


Examples

Basic Usage

Theme-Adaptive Label

Status Indicator Label

Dynamic Color Updates

Localized Content

Container with Multiple Labels



Best Practices

  1. Use KtColor.Empty for inheritance: Allow labels to inherit colors from their container for consistent theming

  2. Leverage theme events: The control handles theme changes automaticallyโ€”no manual intervention needed

  3. Semantic colors: Use appropriate KtColor values (Success, Error, Warning) for status indicators

  4. Dispose properly: When removing labels programmatically, ensure proper disposal to prevent memory leaks

  5. Test both themes: Verify your UI works correctly in both light and dark modes

Last updated

Was this helpful?