private void button1_Click(object sender, EventArgs e)
{
// Create a Graphics object for the Control.
Graphics g = label1.CreateGraphics();
Font nf = new Font(label1.Font, FontStyle.Bold);
// Get the Size needed to accommodate the formatted Text.
Size preferredSize = g.MeasureString(
label1.Text, nf).ToSize();
label1.Font = nf;
label1.ClientSize = new Size(preferredSize.Width,preferredSize.Height); // you could add some padding space to the width and height here
// Clean up the Graphics object.
g.Dispose();
}
|