Link to home
Start Free TrialLog in
Avatar of wardog_33
wardog_33

asked on

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
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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
Avatar of wardog_33
wardog_33

ASKER

Yes, that is what I'm looking for.
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


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
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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