Siticone BadgeNotification
The SiticoneBadgeSystemNotification is a non-visual component that attaches a lightweight notification badge (counter) to any existing WinForms control.
It automatically handles positioning, resizing, and visibility, ensuring the badge always overlays the target control correctly, even when the parent form is resized.
Core Properties
Essential properties to connect the badge to a control and manage its data.
| Property | Type | Description & Usage Example |
|---|---|---|
TargetControl |
Control | badge.TargetControl = btnInbox; The control (e.g., Button, PictureBox, Panel) to which the badge is attached. |
BadgeValue |
int | badge.BadgeValue = 5; The numeric value displayed inside the badge. |
AutoShowHideBadge |
bool |
badge.AutoShowHideBadge = true;
If true, the badge automatically becomes visible when BadgeValue > 0 and hides when 0.
|
Visible |
bool |
badge.Visible = true;
Manually overrides visibility. Setting this property automatically sets AutoShowHideBadge to false.
|
Appearance & Styling
Customize the colors, fonts, and borders of the notification badge.
| Property | Type | Description |
|---|---|---|
BadgeBackColor |
Color | badge.BadgeBackColor = Color.Red; The background fill color of the badge. |
BadgeForeColor |
Color | badge.BadgeForeColor = Color.White; The text color of the number inside the badge. |
BadgeFont |
Font | badge.BadgeFont = new Font("Segoe UI", 9f); The font used to render the badge value. |
BadgeBorderColor |
Color | badge.BadgeBorderColor = Color.White; The color of the ring border around the badge. |
BadgeBorderSize |
int | badge.BadgeBorderSize = 2; Thickness of the border. Set to 0 to remove the border. |
EnableAnimations |
bool | badge.EnableAnimations = true; When true, the badge smoothly fades in and out when visibility changes. |
Position & Layout
Fine-tune exactly where the badge appears relative to the target control.
| Property | Type | Description |
|---|---|---|
Position |
ControlBadgePosition |
badge.Position = ControlBadgePosition.TopRight;
Preset positions: TopRight, TopLeft, BottomRight, BottomLeft, Center.
|
BadgeTopMargin |
int | Moves the badge down from the top edge. |
BadgeRightMargin |
int | Moves the badge left from the right edge. |
BadgeLeftMargin |
int | Moves the badge right from the left edge. |
BadgeBottomMargin |
int | Moves the badge up from the bottom edge. |
Public Methods
// Forces the badge to appear instantly, bypassing animations.
// Useful for initial load states or when resetting UI.
siticoneBadge1.ShowBadgeImmediate();
// Forces the badge to hide instantly, bypassing animations.
siticoneBadge1.HideBadgeImmediate();
// Recalculates the badge position and redraws it.
// Call this if the TargetControl is moved programmatically without resizing.
siticoneBadge1.RefreshBadge();
// Resets all Top, Bottom, Left, and Right margins to 0.
siticoneBadge1.ResetMargins();
Detailed Usage Examples
Example 1: Shopping Cart Counter
Increments the badge value on a button click. Uses the default AutoShowHideBadge to hide the badge when the cart is empty.
private void InitializeCartBadge()
{
// Setup Badge
badgeCart.TargetControl = btnCart;
badgeCart.BadgeValue = 0;
badgeCart.BadgeBackColor = Color.Crimson;
badgeCart.BadgeForeColor = Color.White;
badgeCart.Position = ControlBadgePosition.TopRight;
// Automatically hide when 0
badgeCart.AutoShowHideBadge = true;
}
private void BtnAddToCart_Click(object sender, EventArgs e)
{
// Simply incrementing the value triggers the update
badgeCart.BadgeValue++;
}
private void BtnClearCart_Click(object sender, EventArgs e)
{
// Setting to 0 automatically hides the badge due to AutoShowHideBadge
badgeCart.BadgeValue = 0;
}
Example 2: Live Notifications (Simulated)
Simulates a background process updating a notification bell. Includes custom styling.
private void SetupNotificationBadge()
{
badgeNotify.TargetControl = picBellIcon;
// Styling: White border for separation from icon
badgeNotify.BadgeBackColor = Color.OrangeRed;
badgeNotify.BadgeBorderColor = Color.White;
badgeNotify.BadgeBorderSize = 2;
// Fine-tune position to overlap the icon corner slightly
badgeNotify.Position = ControlBadgePosition.TopRight;
badgeNotify.BadgeTopMargin = -5;
badgeNotify.BadgeRightMargin = -5;
}
private void Timer_Tick(object sender, EventArgs e)
{
// Simulate receiving data
int serverCount = GetNewMessagesCount();
// Update badge
badgeNotify.BadgeValue = serverCount;
// Optional: Change color based on urgency
if (serverCount > 10)
badgeNotify.BadgeBackColor = Color.Red;
else
badgeNotify.BadgeBackColor = Color.OrangeRed;
}
Example 3: Manual Visibility Control
Using the badge as a boolean status indicator (e.g., "Update Available") rather than a counter. We disable auto-hide and manage Visible manually.
private void CheckForUpdates()
{
badgeUpdate.TargetControl = btnSettings;
// Disable auto-logic because we want to show '1' or '!' manually
badgeUpdate.AutoShowHideBadge = false;
badgeUpdate.Visible = false; // Hidden by default
// Style as a small dot or exclamation
badgeUpdate.BadgeValue = 1;
badgeUpdate.BadgeBackColor = Color.LimeGreen;
bool updateFound = Service.HasUpdates();
if (updateFound)
{
// Manually show the badge
badgeUpdate.Visible = true;
// Force instant appearance
badgeUpdate.ShowBadgeImmediate();
}
}