Articles in this section
Category / Section

How to get the index of panels loaded in the WinForms StatusBarAdvPanel being currently painted?

2 mins read

Handle the paint event

The index of the WinForms 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 WinForms StatusBarAdv panel

Figure 1: Before painting the StatusBarAdv panel

Show the WinForms StatusBarAdv panel is painted in index number 3

Figure 2: StatusBarAdv panel is painted in index number 3

Show the WinForms StatusBarAdv panel is painted in index number 2

Figure 3: StatusBarAdv panel is painted in index number 2

Show the WinForms StatusBarAdv panel is painted in index number 1

Figure 4: StatusBarAdv panel is painted in index number 1

Show the WinForms StatusBarAdv panel is painted in index number 0

Figure 5: StatusBarAdv panel is painted in index number 0

Show all panel is painted in WinForms StatusBarAdv

Figure 6: After painting the StatusBarAdv panel

Samples:

C#: StatusBarAdv_Index_C#

VB: StatusBarAdv_Index_VB

 

Conclusion

I hope you enjoyed learning about how to drag and drop the merged Cells in WinForms GridControl.

You can refer to our WinForms StatusBarAdvPanel’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms StatusBarAdvPanel documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms StatusBarAdvPanel and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied