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

Материал из .Net Framework эксперт
Версия от 12:09, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

DockStyle.Bottom

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


DockStyle.Fill

 

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


DockStyle.Left

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


DockStyle.None

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


DockStyle.Right

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


DockStyle.Top

 

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