Pulsing Text Size

lxXTaCoXxl 2 Tallied Votes 174 Views Share

I used a label inside my snippet just to test it; but this will simply increment and decrement a float value by 0.2f between the values specified in the conditionals. I have it updating between 8f and 15f. Must be run on a timer (make sure the interval is low "ex: mine is on 1ms"). It's still a little buggy and by buggy I mean it bugs me that it's jerky. It's not smooth transition.

***UPDATE***
I fixed the jerky bug inside of the source.

//Line 35
FontSize += 0.25f;

//Line 44
FontSize -= 0.25f;

Yes this will work with anything that has a font. Just simply change it from a label.

Example:

textBox1.Font = new Font("OCR A Extended", FontSize, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0));

Most of use don't know the exact font names so just change your text to the font you want, then go into the designer source of the form and get the value from the font assignment in there.

Enjoy,
Jamie - Studio 41 Games (Owner/Head Developer)

ddanbe commented: Great! +14
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Pulse_Label
{
    public partial class Form1 : Form
    {
        private float FontSize = 8f;
        private bool PulseCompleted = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Font = new Font("OCR A Extended", FontSize, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            label1.Location = new Point((this.Size.Width / 2) - (label1.Size.Width) / 2,
                                        (this.Size.Height / 2) - (label1.Size.Height / 2));
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!PulseCompleted)
            {
                if (FontSize < 15f)
                    FontSize += 0.2f;

                else if (FontSize >= 15f)
                    PulseCompleted = true;
            }

            else
            {
                if (FontSize > 8f)
                    FontSize -= 0.2f;

                else if (FontSize <= 8f)
                    PulseCompleted = false;
            }

            label1.Font = new Font("OCR A Extended", FontSize, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            label1.Location = new Point((this.Size.Width / 2) - (label1.Size.Width) / 2,
                (this.Size.Height / 2) - (label1.Size.Height / 2));
        }
    }
}
skatamatic 371 Practically a Posting Shark

Neat little snipet.

1 Thing though. The max speed of a winforms timer tick event is actually about 20-30ms, so setting it to 1ms is actually just taxing your cpu a bit more than is necessary.

lxXTaCoXxl 26 Posting Whiz in Training

Yes but setting it at 25ms makes the transitions jumpy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.