)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize the caption label forecolor on WinForms MetroForm when mouse hovering?

Platform: WinForms |
Control: MetroForm |
Published Date: April 6, 2018 |
Last Revised Date: January 6, 2020 |
.NET Framework: 4

Customize the caption label

The MetroForm CaptionLabel Forecolor can be changed when mouse hovering. It can be achieved by handling the MouseEnter and MouseLeave events. The following code demonstrates the same.

C#

// Caption labels
for(int i = 0; i < this.CaptionLabels.Count; i++)
{
  CaptionLabel item = this.CaptionLabels[i];
  item.LabelMouseEnter += new CaptionLabel.MouseEnter(item_LabelMouseEnter);
  item.LabelMouseLeave += new CaptionLabel.MouseLeave(item_LabelMouseLeave);
  item.LabelMouseDown += new CaptionLabel.MouseDown(item_LabelMouseDown);
}
/// <summary>
/// Occurs on Mouse Pointer Leave
/// </summary>
void item_LabelMouseLeave(object sender, LabelMouseLeaveEventArgs e)
{
  if((sender as CaptionLabel) != null)
  {
    (sender as CaptionLabel).ForeColor = Color.White;
  }
}
/// <summary>
/// Occurs on Mouse Pointer Enter
/// </summary>
void item_LabelMouseEnter(object sender, LabelMouseEnterEventArgs e)
{
  if((sender as CaptionLabel) != null)
  {
    (sender as CaptionLabel).ForeColor = Color.Yellow;
  }
}

VB

' Caption labels
For i As Integer = 0 To Me.CaptionLabels.Count - 1
  Dim item As CaptionLabel = Me.CaptionLabels(i)
  AddHandler item.LabelMouseEnter, AddressOf item_LabelMouseEnter
  AddHandler item.LabelMouseLeave, AddressOf item_LabelMouseLeave
  AddHandler item.LabelMouseDown, AddressOf item_LabelMouseDown
Next i
''' <summary>
''' Occurs on Mouse Pointer Leave
''' </summary>
Private Sub item_LabelMouseLeave(ByVal sender As Object, ByVal e As LabelMouseLeaveEventArgs)
  If(TryCast(sender, CaptionLabel)) IsNot Nothing Then
    TryCast(sender, CaptionLabel).ForeColor = Color.White
  End If
End Sub
''' <summary>
''' Occurs on Mouse Pointer Enter
''' </summary>
Private Sub item_LabelMouseEnter(ByVal sender As Object, ByVal e As LabelMouseEnterEventArgs)
  If(TryCast(sender, CaptionLabel)) IsNot Nothing Then
    TryCast(sender, CaptionLabel).ForeColor = Color.Yellow
  End If
End Sub

 

Screenshot

Customize the caption label fore color on MetroForm

 

Samples:

C#:  MetroFormExample

VB:  MetroFormExample

Reference link: https://help.syncfusion.com/windowsforms/metro-form/customization

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon