Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


CSharp Programming

CSharp > Code Examples

Anchor Two Buttons

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
Anchor Two Buttons using System; using System.Drawing; using System.Windows.Forms; class TwoButtonsAnchor: Form { public static void Main() { Application.Run(new TwoButtonsAnchor()); } public TwoButtonsAnchor() { ResizeRedraw = true; int cxBtn = 5 * Font.Height; int cyBtn = 2 * Font.Height; int dxBtn = Font.Height; Button btn = new Button(); btn.Parent = this; btn.Text = "&Larger"; btn.Location = new Point(dxBtn, dxBtn); btn.Size = new Size(cxBtn, cyBtn); btn.Click += new EventHandler(ButtonLargerOnClick); btn = new Button(); btn.Parent = this; btn.Text = "&Smaller"; btn.Location = new Point(ClientSize.Width - cxBtn - dxBtn, ClientSize.Height - cyBtn - dxBtn); btn.Size = new Size(cxBtn, cyBtn); btn.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; btn.Click += new EventHandler(ButtonSmallerOnClick); } void ButtonLargerOnClick(object obj, EventArgs ea) { Console.WriteLine("large"); } void ButtonSmallerOnClick(object obj, EventArgs ea) { Console.WriteLine("small"); } }