Owner draw status bar text

R

Robert Scheer

Hi.

How cai I center text on a owner draw status bar using vb.net? One of
the panels of my status bar needs to be red and have some centered
text in it. I discovered how to make it red, but didn't find a way to
center text on the panel.

Thanks,
Robert Scheer
 
K

Ken Tucker [MVP]

Hi,


Use a drawstring which accepts a string format. Set the format to
center the text.

Private Sub StatusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As
System.Windows.Forms.StatusBarDrawItemEventArgs) Handles StatusBar1.DrawItem

Dim g As Graphics = sbdevent.Graphics

Dim sbp As StatusBarPanel = sbdevent.Panel

Dim br As Brush

Dim sf As New StringFormat

Dim r As RectangleF = RectangleF.op_Implicit(sbdevent.Bounds)

sf.Alignment = StringAlignment.Center

br = New SolidBrush(Color.Red)

g.FillRectangle(br, r)

g.DrawString(sbp.Text, StatusBar1.Font, Brushes.White, r, sf)

End Sub



Ken
 
R

Robert Scheer

Hi Ken,

thanks, it worked. But what is that op_implicit method you did use? It
does not appear in the intellisense.

Thanks,
Robert Scheer
 
K

Ken Tucker [MVP]

Hi,

In the visual studio options -> text editor -> Basic -> In the
statement completion section uncheck the hide advanced members box.

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top