Wednesday, February 5, 2014

How to make font resize automatically based on label size?

        private void Form1_Resize(object sender, EventArgs e)
        {
            pixels = Math.Min(label1.Height, label1.Width/2.8);
            float fontSize = (float)(pixels * 0.8 * 72.0 / 96.0); //this is the magic
            this.Font = new Font("Arial", fontSize, FontStyle.Bold);
        }


No comments:

Post a Comment