Comment is too long so I'll post a new answer. Paste the TextBox and Label into the Form and see if MeasureClientSize works.
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void text1_TextChanged(object sender, EventArgs e) {
label1.AutoSize = false; //
label1.Text = ((TextBox)sender).Text;
using (var g = label1.CreateGraphics()) {
label1.ClientSize = MeasureClientSize(g, label1, 100);
}
}
internal static Size MeasureClientSize(Graphics g, Label label, int maxWidth) {
Size size;
int tmpWidth = maxWidth - (label.Padding.Left + label.Padding.Right);
if (label.UseCompatibleTextRendering) {
using (StringFormat stringFormat = CreateStringFormat(label)) {
SizeF tmpSizeF = g.MeasureString(label.Text, label.Font, tmpWidth, stringFormat);
size = new Size(Roundup(tmpSizeF.Width), Roundup(tmpSizeF.Height));
}
} else {
TextFormatFlags flags = CreateTextFormatFlags(label);
Size tmpSize = new Size(tmpWidth, 1);
size = TextRenderer.MeasureText(g, label.Text, label.Font, tmpSize, flags);
}
return new Size(size.Width + label.Padding.Left + label.Padding.Right,
size.Height + label.Padding.Top + label.Padding.Bottom);
}
internal static int Roundup(double value) {
return (int)Math.Truncate((value * 10 + 9) / 10);
}
internal static StringFormat CreateStringFormat(Label label) {
// Please check .NET source and rewrite it.
return new StringFormat(StringFormatFlags.FitBlackBox);
}
internal static TextFormatFlags CreateTextFormatFlags(Label label) {
// Please check .NET source and rewrite it.
return TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak;
}
}