Avatar of awp5379
awp5379

asked on 

How to extended status strip label for multi colored font?

How can I extend the status strip label for multi-colored text? example:

I have a status strip label with the text "Refresh". I want the "R" to be in red and "efresh" to be in black on the same label.

Obviously, a new class needs to inherit from ToopStripStatusLabel and implement iextenderprovider........but I'm stuck on how to incorp. multi font types. Secondly, how does the status strip consume the extended control.

Visual Basic ClassicVisual Basic.NET

Avatar of undefined
Last Comment
Jorge Paulino
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of awp5379
awp5379

ASKER

jpaulino,

That is very close to what I need, but I am having one problem. The font I am using is Arial, 22pt, style=Bold.

When the OnPaint finishes, the statusstrip height gets changed to 22 (caused from the .Autosize) and the text is cut off. If I turn off the autosize or adjust the statusstrip.height in the method, the form painting gets screwed up.
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Ok, then try this way (with a few ajustments):

    Private Sub tsMenuItem_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles tsMenuItem.Paint
        tsMenuItem.Text = String.Empty
        tsMenuItem.AutoSize = False
 
        ' You may need to change this values (ajustments)
        ' -------------------------------------------------
        Dim ItemHeight As Byte = 4
        Dim ReduceGap As Byte = 8
        ' -------------------------------------------------
 
        Dim strFirst As String = "R"
        Dim sz As SizeF = e.Graphics.MeasureString(strFirst, tsMenuItem.Font, tsMenuItem.Width)
        e.Graphics.DrawString(strFirst, tsMenuItem.Font, Brushes.Red, 0, ItemHeight)
 
        Dim strSecond As String = "efresh"
        e.Graphics.DrawString(strSecond, tsMenuItem.Font, Brushes.Black, sz.Width - ReduceGap, ItemHeight)
 
        sz = e.Graphics.MeasureString(strFirst + strSecond, tsMenuItem.Font, 120)
        tsMenuItem.Width = sz.Width
 
    End Sub

Open in new window

Avatar of awp5379
awp5379

ASKER

Got it. I needed to resize the parent (statusstrip itself). The tsMenuItem's height was correct, but the .AutoSize causes the statusstrip's height to get changed. It needs to be reset.

Thanks!
Avatar of awp5379
awp5379

ASKER

Thorough solution. Thanks!
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Glad I could help!

jpaulino
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo