)
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 get the index of panels loaded in the WinForms StatusBarAdvPanel being currently painted?

Platform: WinForms |
Control: StatusBarAdvPanel |
Published Date: October 9, 2015 |
Last Revised Date: January 27, 2020

Handle the paint event

The index of the StatusBarAdvPanel being painted can be achieved by handling the paint event of the StatusBarAdvPanel.

C#

//Hooks the panel paint event
for (int i = 0; i < statusBarAdv1.Panels.Length; i++)
    statusBarAdv1.Panels[i].Paint += StatusBarPanel_Paint;
/// <summary>
/// StatusbarAdvPanel paint event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StatusBarPanel_Paint(object sender, PaintEventArgs e)
{
    for (int i = 0; i < statusBarAdv1.Panels.Length; i++)
    {
        if (statusBarAdv1.Panels[i].Text == (sender as StatusBarAdvPanel).Text)
        {
            if (i == 0)
                this.statusBarAdv1.Panels[0].BackColor = Color.Red;
            else if (i == 1)
                this.statusBarAdv1.Panels[1].BackColor = Color.Green;
            else if(i == 2)
                this.statusBarAdv1.Panels[2].BackColor = Color.Blue;
            else if (i == 3)
                this.statusBarAdv1.Panels[3].BackColor = Color.Orange;
            MessageBox.Show("Index of the panel being painted is " + i.ToString());
        }
    }
}

VB

'Hooks the panel paint event
For i As Integer = 0 To statusBarAdv1.Panels.Length - 1
    AddHandler statusBarAdv1.Panels(i).Paint, AddressOf StatusBarPanel_Paint
Next i
''' <summary>
''' StatusbarAdvPanel paint event
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub StatusBarPanel_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
    For i As Integer = 0 To statusBarAdv1.Panels.Length - 1
        If statusBarAdv1.Panels(i).Text = (TryCast(sender, StatusBarAdvPanel)).Text Then
 If i = 0 Then
    Me.statusBarAdv1.Panels(0).BackColor = Color.Red
 ElseIf i = 1 Then
    Me.statusBarAdv1.Panels(1).BackColor = Color.Green
 ElseIf i = 2 Then
    Me.statusBarAdv1.Panels(2).BackColor = Color.Blue
 ElseIf i = 3 Then
    Me.statusBarAdv1.Panels(3).BackColor = Color.Orange
 End If
 MessageBox.Show("Index of the panel being painted is " & i.ToString())
        End If
    Next i
End Sub

 

Show the before painting the StatusBarAdv panel

Figure 1: Before painting the StatusBarAdv panel

Show the StatusBarAdv panel is painted in index number 3

Figure 2: StatusBarAdv panel is painted in index number 3

Show the StatusBarAdv panel is painted in index number 2

Figure 3: StatusBarAdv panel is painted in index number 2

Show the StatusBarAdv panel is painted in index number 1

Figure 4: StatusBarAdv panel is painted in index number 1

Show the StatusBarAdv panel is painted in index number 0

Figure 5: StatusBarAdv panel is painted in index number 0

Show all panel is painted in StatusBarAdv

Figure 6: After painting the StatusBarAdv panel

Samples:

C#: StatusBarAdv_Index_C#

VB: StatusBarAdv_Index_VB

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