2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Handle the paint eventThe 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
Figure 1: Before painting the StatusBarAdv panel Figure 2: StatusBarAdv panel is painted in index number 3 Figure 3: StatusBarAdv panel is painted in index number 2 Figure 4: StatusBarAdv panel is painted in index number 1 Figure 5: StatusBarAdv panel is painted in index number 0 Figure 6: After painting the StatusBarAdv panel Samples: |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.