Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Device Independent Button

using System; using System.Drawing; using System.Windows.Forms; class MyClass: Form {     [STAThread]     public static void Main()     {         Application.Run(new MyClass());     }     public MyClass()     {         int fontHeight = Font.Height;         ClientSize = new Size(fontHeight * 30, fontHeight * 10);         Button btn = new Button();         btn.Parent = this;         btn.Text = "Button";         btn.Size = new Size(17 * fontHeight / 2, 7 * fontHeight / 4);         btn.Location = new Point((ClientSize.Width - btn.Width) / 2,                                  (ClientSize.Height - btn.Height) / 2);     } }