• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Resizing Text at runtime

Hello Experts:
I need a little help with one of my projects. I have created a screensaver that displays Sales Reminders to our sales people. The reminders come from a text file shared on the network. Anyway, When the screensaver starts, it displays the list just fine. (only 5 allowed) The problem I'm having is that I would like to start with the top-most reminder and change the text size/font so that it will grow till it reaches the screen width, then make it shrink back to normal. I also wanted a random color. Here is the code I use for the timer event:

  Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static r As Integer
      Static c As Integer
        Dim y As Integer
        Dim z As Integer        
        Dim mc As Color

        If c < 5 Then
            Randomize() ' Initialize random-number generator.
            y = CInt(Int((255 * Rnd()) + 1)) ' Generate random value between 1 and 255.
            z = CInt(Int((255 * Rnd()) + 1)) ' Generate random value between 1 and 255.
            MyLabels(r).ForeColor = mc.FromArgb(255, y, z)
        End If

        c += 1

        If c = 5 Then
            If r <= 5 Then
                r += 1
            End If
            c = 0
        End If
    End Sub

Pretty simple huh? Well the random coloring looks just great, but I can't seem to figure out how to increase the text size.
Any and all help is appreciated. Because I need a quick answer I will award the full 500 points for a quick solution.

Thanks,
James
0
wardog_33
Asked:
wardog_33
  • 3
  • 3
1 Solution
 
Bob LearnedCommented:
Do you want it to change colors as the font size is changing?  In other words, do you want all the operations to be within the Tick event?

Bob
0
 
wardog_33Author Commented:
Yes, that is what I'm looking for.
0
 
Bob LearnedCommented:
How many labels are there?

What does this block do (what are r and c)?
c += 1

If c = 5 Then
   If r <= 5 Then
      r += 1
   End If
  c = 0
End If

Bob


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
wardog_33Author Commented:
Sorry,
c represents the record count
r is the current label control in an array of labels:

Don't worry about the code block you referenced earlier. It will probably go through more changes.
The code is me trying to hardcode when to switch to a different label. There are 5 or less labels.

What I need to know is how to change the font size at run time, preferably in a looping construct in a timer event.

Thanks,
James
0
 
Bob LearnedCommented:
Ok, with that out of the way:

Do you want the font size to grow until the text fills the form?

Start with this:

  Public Sub GrowLabelToFillScreen(ByVal owner As Form, ByVal label As Label)

    Dim fontTest As Font = New Font(label.Font.Name, label.Font.Size + 1)

    Dim widthText As Integer = owner.CreateGraphics.MeasureString(label.Text, fontTest).Width

    If widthText < owner.ClientSize.Width Then
      label.Font = fontTest
    End If

  End Sub

Usage:
  GrowLabelToFillScreen(Me, MyLabels(0))

Bob
0
 
wardog_33Author Commented:
Perfect...
The code I needed was the;
Dim fontTest As Font = New Font(label.Font.Name, label.Font.Size + 1)

I was trying set a font size using the font.size, but it would always complain about being read only.
Didn't realize I needed to create a new font.

Thanks!
James
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now