Directory tree and property grid

image_pdfimage_print



   

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace DirectoryTreeHost
{
  /// <summary>
  /// Summary description for DirectoryTreeHost.
  /// </summary>
  public class DirectoryTreeHost : System.Windows.Forms.Form
  {
    private DirectoryTreeControl.DirectoryTree dirTree;
    private System.Windows.Forms.PropertyGrid propertyGrid1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public DirectoryTreeHost()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.dirTree = new DirectoryTreeControl.DirectoryTree();
      this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
      this.SuspendLayout();
      // 
      // dirTree
      // 
      this.dirTree.Drive = &#039;C&#039;;
      this.dirTree.ImageIndex = -1;
      this.dirTree.Location = new System.Drawing.Point(292, 12);
      this.dirTree.Name = "dirTree";
      
      this.dirTree.SelectedImageIndex = -1;
      this.dirTree.Size = new System.Drawing.Size(276, 272);
      this.dirTree.TabIndex = 0;
      // 
      // propertyGrid1
      // 
      this.propertyGrid1.CommandsVisibleIfAvailable = true;
      this.propertyGrid1.LargeButtons = false;
      this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
      this.propertyGrid1.Location = new System.Drawing.Point(12, 12);
      this.propertyGrid1.Name = "propertyGrid1";
      this.propertyGrid1.SelectedObject = this.propertyGrid1;
      this.propertyGrid1.Size = new System.Drawing.Size(260, 272);
      this.propertyGrid1.TabIndex = 1;
      this.propertyGrid1.Text = "propertyGrid1";
      this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window;
      this.propertyGrid1.ViewForeColor = System.Drawing.SystemColors.WindowText;
      // 
      // DirectoryTreeHost
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.ClientSize = new System.Drawing.Size(592, 298);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.propertyGrid1,
                                      this.dirTree});
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.Name = "DirectoryTreeHost";
      this.Text = "DirectoryTreeHost";
      this.Load += new System.EventHandler(this.DirectoryTreeHost_Load);
      this.ResumeLayout(false);

    }
    #endregion

    private void DirectoryTreeHost_Load(object sender, System.EventArgs e)
    {


    }

    public static void Main()
    {
      Application.Run(new DirectoryTreeHost());
    }
  }
}


           
          


DirectoryTreeHost.zip( 66 k)

Dock Two Buttons

image_pdfimage_print
   
 


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   = "&amp;Larger";
          btn.Height = 2 * Font.Height;
          btn.Dock   = DockStyle.Top;
          btn.Click += new EventHandler(ButtonLargerOnClick);
          
          btn = new Button();
          btn.Parent = this;
          btn.Text   = "&amp;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");
     }
}

    


Dock Style: None

image_pdfimage_print


   


  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

image_pdfimage_print


   


  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

image_pdfimage_print


   

  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

image_pdfimage_print


   

  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

image_pdfimage_print


   


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

  }