StatusBar.BackColor = Color.Yellow fails

  • Thread starter Thread starter Fred Morrison
  • Start date Start date
F

Fred Morrison

OK, the direct method of setting the background color on a text-only (no
panels) statusbar control seems to fail:

Me.StatusBar1.Text = "<whatever> failed.>
Me.StatusBar1.Backcolor = Color.Yellow ' nothing changes
Me.StatusBar1.Refresh ' doesn't help either.

What convoluted work-around (must be if the simple, direct method fails) is
there for this?
 
* "Fred Morrison said:
OK, the direct method of setting the background color on a text-only (no
panels) statusbar control seems to fail:

Me.StatusBar1.Text = "<whatever> failed.>
Me.StatusBar1.Backcolor = Color.Yellow ' nothing changes
Me.StatusBar1.Refresh ' doesn't help either.

This property is not implemented for the StatusBar control. You may
want to define an ownerdrawn panel and draw its background by handling
the panel's 'DrawItem' event.
 
I found this online somewhere, hope this helps

Public Class ColoredStatusBar

Inherits StatusBar

Private m_BackColor As Color = Color.Blue

Public Sub New()

MyBase.New()

Me.SetStyle(ControlStyles.UserPaint, True)

Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)

End Sub

Public Shadows Property BackColor() As Color

Get

Return m_BackColor

End Get

Set(ByVal Value As Color)

m_BackColor = Value

Me.Invalidate()

End Set

End Property

Protected Overrides Sub OnPaint( _

ByVal e As System.Windows.Forms.PaintEventArgs)

e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), _

e.ClipRectangle)

e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), _

e.ClipRectangle.X, e.ClipRectangle.Y)

If Me.SizingGrip = True Then

ControlPaint.DrawSizeGrip(e.Graphics, Me.BackColor, e.ClipRectangle)

End If

End Sub

End Class
 
Back
Top