Csharp/C Sharp by API/System.Windows.Forms/DockStyle

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

DockStyle.Bottom

<source lang="csharp">

 using System;
 using System.Drawing;
 using System.Collections;
 using System.ruponentModel;
 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() + 
       "\nDock: " + button1.Dock.ToString();
   }
   static void Main() 
   {
     Application.Run(new AnchorForm());
   }
 }
  
 </source>


DockStyle.Fill

<source lang="csharp">

 using System;
 using System.Drawing;
 using System.Collections;
 using System.ruponentModel;
 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() + 
       "\nDock: " + button1.Dock.ToString();
   }
   static void Main() 
   {
     Application.Run(new AnchorForm());
   }
 }
  
 </source>


DockStyle.Left

<source lang="csharp">

 using System;
 using System.Drawing;
 using System.Collections;
 using System.ruponentModel;
 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() + 
       "\nDock: " + button1.Dock.ToString();
   }
   static void Main() 
   {
     Application.Run(new AnchorForm());
   }
 }
  
 </source>


DockStyle.None

<source lang="csharp">

 using System;
 using System.Drawing;
 using System.Collections;
 using System.ruponentModel;
 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() + "\nDock: " + button1.Dock.ToString();
     
   }
   static void Main() 
   {
     Application.Run(new AnchorForm());
   }
 }
  
 </source>


DockStyle.Right

<source lang="csharp">

 using System;
 using System.Drawing;
 using System.Collections;
 using System.ruponentModel;
 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() + 
       "\nDock: " + button1.Dock.ToString();
   }
   static void Main() 
   {
     Application.Run(new AnchorForm());
   }
 }
  
 </source>


DockStyle.Top

<source lang="csharp">

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");
    }

}

 </source>