using System; using System.Drawing; using System.Windows.Forms; class TwoButtonsDock: Form { public static void Main() { Application.Run(new TwoButtonsDock()); } public TwoButtonsDock() { ResizeRedraw = true; Button btn = new Button(); btn.Parent = this; btn.Text = "&Larger"; btn.Height = 2 * Font.Height; btn.Dock = DockStyle.Top; btn.Click += new EventHandler(ButtonLargerOnClick); btn = new Button(); btn.Parent = this; btn.Text = "&Smaller"; btn.Height = 2 * Font.Height; btn.Dock = DockStyle.Bottom; btn.Click += new EventHandler(ButtonSmallerOnClick); } void ButtonLargerOnClick(object obj, EventArgs ea) { Console.WriteLine("large"); } void ButtonSmallerOnClick(object obj, EventArgs ea) { Console.WriteLine("small"); } }
Author: coder
Dock Style: None
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class AnchorForm : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; public AnchorForm() { InitializeComponent(); CenterToScreen(); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1}); this.Text = "Anchoring (and Docking) Controls"; // dock None button1.Dock = DockStyle.None; button1.Text = "Anchor: " + button1.Anchor.ToString() + " Dock: " + button1.Dock.ToString(); } static void Main() { Application.Run(new AnchorForm()); } }
Dock style: Fill
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class AnchorForm : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; public AnchorForm() { InitializeComponent(); CenterToScreen(); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1}); this.Text = "Anchoring (and Docking) Controls"; // dock Fill button1.Dock = DockStyle.Fill; button1.Text = "Anchor: " + button1.Anchor.ToString() + " Dock: " + button1.Dock.ToString(); } static void Main() { Application.Run(new AnchorForm()); } }
Dock Style: Right
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class AnchorForm : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; public AnchorForm() { InitializeComponent(); CenterToScreen(); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1}); this.Text = "Anchoring (and Docking) Controls"; //dock Right button1.Dock = DockStyle.Right; button1.Text = "Anchor: " + button1.Anchor.ToString() + " Dock: " + button1.Dock.ToString(); } static void Main() { Application.Run(new AnchorForm()); } }
Dock Style: Left
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class AnchorForm : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; public AnchorForm() { InitializeComponent(); CenterToScreen(); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1}); this.Text = "Anchoring (and Docking) Controls"; // dock Left button1.Dock = DockStyle.Left; button1.Text = "Anchor: " + button1.Anchor.ToString() + " Dock: " + button1.Dock.ToString(); } static void Main() { Application.Run(new AnchorForm()); } }
Dock Style: Bottom
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class AnchorForm : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; public AnchorForm() { InitializeComponent(); CenterToScreen(); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1}); this.Text = "Anchoring (and Docking) Controls"; //dock Bottom button1.Dock = DockStyle.Bottom; button1.Text = "Anchor: " + button1.Anchor.ToString() + " Dock: " + button1.Dock.ToString(); } static void Main() { Application.Run(new AnchorForm()); } }
Dock Style: Top
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class AnchorForm : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; public AnchorForm() { InitializeComponent(); CenterToScreen(); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1}); this.Text = "Anchoring (and Docking) Controls"; // dock Top button1.Dock = DockStyle.Top; button1.Text = "Anchor: " + button1.Anchor.ToString() + " Dock: " + button1.Dock.ToString(); } static void Main() { Application.Run(new AnchorForm()); } }