?
Solved

Resizing Text at runtime

Posted on 2005-03-28
6
Medium Priority
?
218 Views
Last Modified: 2010-04-23
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
Comment
Question by:wardog_33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13652679
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
 
LVL 1

Author Comment

by:wardog_33
ID: 13653132
Yes, that is what I'm looking for.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13653246
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:wardog_33
ID: 13654124
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 13654186
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
 
LVL 1

Author Comment

by:wardog_33
ID: 13654548
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question