Question: I have a label that shows the file name .. I had to set `AutoSize` of the label to `False` for designing.  

So when the file name text got longer than label size.. it got cut like in the picture.

![enter image description here](https://i.stack.imgur.com/M9zkb.jpg)

```
label1.Size = new Size(200, 32);
label1.AutoSize = false;

```

How do I re-size the text automatically to fit the label size, when the text is longer than the label size?

Answer: 
Based on the [article](http://tech.pro/tutorial/691/csharp-tutorial-font-scaling) provided by @brgerner, I'll provide the alternative implementation here, as that one marked as an answer is not so efficient nor complete as this one below:

```
public class FontWizard
{
    public static Font FlexFont(Graphics g, float minFontSize, float maxFontSize, Size layoutSize, string s, Font f, out SizeF extent)
    {
        if (maxFontSize == minFontSize)
            f = new Font(f.FontFamily, minFontSize, f.Style);

        extent = g.MeasureString(s, f);

        if (maxFontSize <= minFontSize)
            return f;

        float hRatio = layoutSize.Height / extent.Height;
        float wRatio = layoutSize.Width / extent.Width;
        float ratio = (hRatio < wRatio) ? hRatio : wRatio;

        float newSize = f.Size * ratio;

        if (newSize < minFontSize)
            newSize = minFontSize;
        else if (newSize > maxFontSize)
            newSize = maxFontSize;

        f = new Font(f.FontFamily, newSize, f.Style);
        extent = g.MeasureString(s, f);

        return f;
    }

    public static void OnPaint(object sender, PaintEventArgs e, string text)
    {
        var control = sender as Control;
        if (control == null)
            return;

        control.Text = string.Empty;    //delete old stuff
        var rectangle = control.ClientRectangle;

        using (Font f = new System.Drawing.Font("Microsoft Sans Serif", 20.25f, FontStyle.Bold))
        {
            SizeF size;
            using (Font f2 = FontWizard.FlexFont(e.Graphics, 5, 50, rectangle.Size, text, f, out size))
            {
                PointF p = new PointF((rectangle.Width - size.Width) / 2, (rectangle.Height - size.Height) / 2);
                e.Graphics.DrawString(text, f2, Brushes.Black, p);
            }
        }
    }
}

```

and the usage:

```
val label = new Label();
label.Paint += (sender, e) => FontWizard.OnPaint(sender, e, text);

```
With inspiration from @bnguyen82 i came up with something that works all the way.

```
public static void ScaleLabel(Label label, float stepSize = 0.5f)
{
    //decrease font size if text is wider or higher than label
    while (lblTextSize() is Size s && s.Width > label.Width || s.Height > label.Height)
    {
        label.Font = new Font(label.Font.FontFamily, label.Font.Size - stepSize, label.Font.Style);
    }

    //increase font size if label width is bigger than text size
    while (label.Width > lblTextSize().Width)
    {
        var font = new Font(label.Font.FontFamily, label.Font.Size + stepSize, label.Font.Style);
        var nextSize = TextRenderer.MeasureText(label.Text, font);

        //dont make text width or hight bigger than label
        if (nextSize.Width > label.Width || nextSize.Height > label.Height)
            break;

        label.Font = font;
    }

    Size lblTextSize() => TextRenderer.MeasureText(label.Text,
        new Font(label.Font.FontFamily, label.Font.Size, label.Font.Style));
}

```

PS: In order for this to work the label needs to have `AutoSize = false` and either to be `docked` or `anchored`.