Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I resize a Button to fit its text?

Get a Graphics object for the button and use its MeasureString method to compute the width you need.

using ( Graphics g = button1.CreateGraphics() )
  float w = g.MeasureString( button1.Text, button1.Font ).Width;
button1.Width = (int) w + 12; // 12 is for the margins

Contributed from George Shepherd's Windows Forms FAQ