Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Calculate Button size based on its Text

using System; using System.Drawing; using System.Windows.Forms; public class ButtonSize : Form {   Button btn;   public ButtonSize()   {         Text = "Button Properties";     Size = new Size(300,200);     btn = new Button();     btn.Parent = this;     btn.Text = "text";     btn.Location = new Point(10,10);     f(btn);   }   static void Main()    {     Application.Run(new ButtonSize());   }   private void f(Button btn)   {     int xSize = 100;     int ySize = 100;     btn.Size = new Size(xSize, ySize);   } }