Get input from password textbox


   


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

  public class TextForm : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button btnPasswordDecoderRing;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox passwordBox;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox capsOnlyBox;
    private System.Windows.Forms.Button btnGetMultiLineText;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox multiLineBox;

        public TextForm()
        {
            InitializeComponent();
        }

    private void InitializeComponent()
    {
      this.capsOnlyBox = new System.Windows.Forms.TextBox();
      this.multiLineBox = new System.Windows.Forms.TextBox();
      this.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.passwordBox = new System.Windows.Forms.TextBox();
      this.btnGetMultiLineText = new System.Windows.Forms.Button();
      this.btnPasswordDecoderRing = new System.Windows.Forms.Button();
      this.label3 = new System.Windows.Forms.Label();
      this.capsOnlyBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
      this.capsOnlyBox.Location = new System.Drawing.Point(14, 176);
      this.capsOnlyBox.Size = new System.Drawing.Size(120, 20);
      this.capsOnlyBox.TabIndex = 3;
      this.multiLineBox.AcceptsReturn = true;
      this.multiLineBox.AcceptsTab = true;
      this.multiLineBox.Location = new System.Drawing.Point(152, 8);
      this.multiLineBox.Multiline = true;
      this.multiLineBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
      this.multiLineBox.Size = new System.Drawing.Size(240, 104);
      this.multiLineBox.TabIndex = 0;
      this.multiLineBox.Text = "Get text from multiline textbox";
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
      this.label1.Location = new System.Drawing.Point(8, 8);
      this.label1.Size = new System.Drawing.Size(136, 56);
      this.label1.TabIndex = 1;
      this.label1.Text = "this is a multiline text box";
      this.label2.Font = new System.Drawing.Font("Comic Sans MS", 12F);
      this.label2.Location = new System.Drawing.Point(14, 144);
      this.label2.Size = new System.Drawing.Size(106, 24);
      this.label2.TabIndex = 4;
      this.label2.Text = "Caps only!!";
      this.passwordBox.Location = new System.Drawing.Point(160, 176);
      this.passwordBox.PasswordChar = '$';
      this.passwordBox.Size = new System.Drawing.Size(232, 20);
      this.passwordBox.TabIndex = 5;
      this.passwordBox.Text = "password";
      this.btnGetMultiLineText.Location = new System.Drawing.Point(13, 72);
      this.btnGetMultiLineText.Size = new System.Drawing.Size(120, 32);
      this.btnGetMultiLineText.TabIndex = 2;
      this.btnGetMultiLineText.Text = "Get Text";
      this.btnGetMultiLineText.Click += new System.EventHandler(this.btnGetMultiLineText_Click);
      this.btnPasswordDecoderRing.Location = new System.Drawing.Point(280, 144);
      this.btnPasswordDecoderRing.Size = new System.Drawing.Size(112, 24);
      this.btnPasswordDecoderRing.TabIndex = 7;
      this.btnPasswordDecoderRing.Text = "Decode Password";
      this.btnPasswordDecoderRing.Click += new System.EventHandler(this.btnPasswordDecoderRing_Click);
      this.label3.Font = new System.Drawing.Font("Comic Sans MS", 12F);
      this.label3.Location = new System.Drawing.Point(152, 144);
      this.label3.Size = new System.Drawing.Size(120, 24);
      this.label3.TabIndex = 6;
      this.label3.Text = "Password Box";
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(408, 221);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {this.btnPasswordDecoderRing,
                                      this.label3,
                                      this.passwordBox,
                                      this.label2,
                                      this.capsOnlyBox,
                                      this.btnGetMultiLineText,
                                      this.label1,
                                      this.multiLineBox});
      this.Text = "TextBox Types";

    }

    protected void btnPasswordDecoderRing_Click (object sender, System.EventArgs e)
    {
      MessageBox.Show(passwordBox.Text, "Your password is:");
    }

    protected void btnGetMultiLineText_Click (object sender, System.EventArgs e)
    {
      MessageBox.Show(multiLineBox.Text, "Here is your text");
    }

        public static void Main(string[] args) 
        {
            Application.Run(new TextForm());
        }
    }


           
          


Set password mask char


   


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

  public class TextForm : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button btnPasswordDecoderRing;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox passwordBox;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox capsOnlyBox;
    private System.Windows.Forms.Button btnGetMultiLineText;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox multiLineBox;

        public TextForm()
        {
            InitializeComponent();
        }

    private void InitializeComponent()
    {
      this.capsOnlyBox = new System.Windows.Forms.TextBox();
      this.multiLineBox = new System.Windows.Forms.TextBox();
      this.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.passwordBox = new System.Windows.Forms.TextBox();
      this.btnGetMultiLineText = new System.Windows.Forms.Button();
      this.btnPasswordDecoderRing = new System.Windows.Forms.Button();
      this.label3 = new System.Windows.Forms.Label();
      this.capsOnlyBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
      this.capsOnlyBox.Location = new System.Drawing.Point(14, 176);
      this.capsOnlyBox.Size = new System.Drawing.Size(120, 20);
      this.capsOnlyBox.TabIndex = 3;
      this.multiLineBox.AcceptsReturn = true;
      this.multiLineBox.AcceptsTab = true;
      this.multiLineBox.Location = new System.Drawing.Point(152, 8);
      this.multiLineBox.Multiline = true;
      this.multiLineBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
      this.multiLineBox.Size = new System.Drawing.Size(240, 104);
      this.multiLineBox.TabIndex = 0;
      this.multiLineBox.Text = "Get text from multiline textbox";
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
      this.label1.Location = new System.Drawing.Point(8, 8);
      this.label1.Size = new System.Drawing.Size(136, 56);
      this.label1.TabIndex = 1;
      this.label1.Text = "this is a multiline text box";
      this.label2.Font = new System.Drawing.Font("Comic Sans MS", 12F);
      this.label2.Location = new System.Drawing.Point(14, 144);
      this.label2.Size = new System.Drawing.Size(106, 24);
      this.label2.TabIndex = 4;
      this.label2.Text = "Caps only!!";
      this.passwordBox.Location = new System.Drawing.Point(160, 176);
      this.passwordBox.PasswordChar = '$';
      this.passwordBox.Size = new System.Drawing.Size(232, 20);
      this.passwordBox.TabIndex = 5;
      this.passwordBox.Text = "password";
      this.btnGetMultiLineText.Location = new System.Drawing.Point(13, 72);
      this.btnGetMultiLineText.Size = new System.Drawing.Size(120, 32);
      this.btnGetMultiLineText.TabIndex = 2;
      this.btnGetMultiLineText.Text = "Get Text";
      this.btnGetMultiLineText.Click += new System.EventHandler(this.btnGetMultiLineText_Click);
      this.btnPasswordDecoderRing.Location = new System.Drawing.Point(280, 144);
      this.btnPasswordDecoderRing.Size = new System.Drawing.Size(112, 24);
      this.btnPasswordDecoderRing.TabIndex = 7;
      this.btnPasswordDecoderRing.Text = "Decode Password";
      this.btnPasswordDecoderRing.Click += new System.EventHandler(this.btnPasswordDecoderRing_Click);
      this.label3.Font = new System.Drawing.Font("Comic Sans MS", 12F);
      this.label3.Location = new System.Drawing.Point(152, 144);
      this.label3.Size = new System.Drawing.Size(120, 24);
      this.label3.TabIndex = 6;
      this.label3.Text = "Password Box";
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(408, 221);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {this.btnPasswordDecoderRing,
                                      this.label3,
                                      this.passwordBox,
                                      this.label2,
                                      this.capsOnlyBox,
                                      this.btnGetMultiLineText,
                                      this.label1,
                                      this.multiLineBox});
      this.Text = "TextBox Types";

    }

    protected void btnPasswordDecoderRing_Click (object sender, System.EventArgs e)
    {
      MessageBox.Show(passwordBox.Text, "Your password is:");
    }

    protected void btnGetMultiLineText_Click (object sender, System.EventArgs e)
    {
      MessageBox.Show(multiLineBox.Text, "Here is your text");
    }

        public static void Main(string[] args) 
        {
            Application.Run(new TextForm());
        }
    }


           
          


PictureBox Click event


   


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

   public class PictureBoxTest : System.Windows.Forms.Form
   {
      private System.Windows.Forms.PictureBox imagePictureBox;
      private System.Windows.Forms.Label promptLabel;

      public PictureBoxTest()
      {
         InitializeComponent();
      }

      private void InitializeComponent()
      {
         this.promptLabel = new System.Windows.Forms.Label();
         this.imagePictureBox = new System.Windows.Forms.PictureBox();
         this.SuspendLayout();

         this.promptLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.promptLabel.Location = new System.Drawing.Point(22, 8);
         this.promptLabel.Name = "promptLabel";
         this.promptLabel.Size = new System.Drawing.Size(124, 56);
         this.promptLabel.TabIndex = 0;
         this.promptLabel.Text = "Click On PictureBox to View Images";
         this.promptLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

         this.imagePictureBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
         this.imagePictureBox.Location = new System.Drawing.Point(34, 72);
         this.imagePictureBox.Name = "imagePictureBox";
         this.imagePictureBox.Size = new System.Drawing.Size(100, 100);
         this.imagePictureBox.TabIndex = 1;
         this.imagePictureBox.TabStop = false;

         this.imagePictureBox.Click += new System.EventHandler(this.imagePictureBox_Click );

         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(168, 189);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {this.imagePictureBox,
                                                                      this.promptLabel});
         this.Text = "PictureBoxTest";
         this.ResumeLayout(false);

      }
      [STAThread]
      static void Main() 
      {
         Application.Run( new PictureBoxTest() );
      }

      private void imagePictureBox_Click(object sender, System.EventArgs e )
      {
         imagePictureBox.Image = Image.FromFile(Directory.GetCurrentDirectory() + "winter.jpg" );
      }

   }



           
          


Control Paint Form


   

/*
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 GDI_Basics
{
    /// <summary>
    /// Summary description for ControlPaint.
    /// </summary>
    public class ControlPaintForm : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public ControlPaintForm()
        {
            //
            // 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()
        {
            // 
            // ControlPaint
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "ControlPaint";
            this.Text = "ControlPaint";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.ControlPaint_Paint);

        }
        #endregion

        private void ControlPaint_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(10, 10, 50, 50), ButtonState.Checked);
            ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(70, 10, 30, 30), ButtonState.Normal);
            ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(110, 10, 20, 20), ButtonState.Checked);
            
            ControlPaint.DrawButton(e.Graphics, new Rectangle(10, 80, 20, 20), ButtonState.Checked);
            ControlPaint.DrawButton(e.Graphics, new Rectangle(50, 80, 20, 20), ButtonState.Flat);
            ControlPaint.DrawButton(e.Graphics, new Rectangle(90, 80, 20, 20), ButtonState.Normal);
            ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(130, 80, 20, 20));
            
            ControlPaint.DrawGrid(e.Graphics, new Rectangle(10, 120, 250, 50), new Size(5, 5), Color.Blue);
            ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(10, 180, 20, 20), ScrollButton.Left, ButtonState.Normal);
            ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(50, 180, 20, 20), ScrollButton.Max, ButtonState.Pushed);
            ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(90, 180, 20, 20), ScrollButton.Up, ButtonState.Normal);
            
            ControlPaint.DrawMenuGlyph(e.Graphics, new Rectangle(10, 220, 20, 20), MenuGlyph.Arrow);
            ControlPaint.DrawMenuGlyph(e.Graphics, new Rectangle(50, 220, 20, 20), MenuGlyph.Checkmark);
            ControlPaint.DrawMenuGlyph(e.Graphics, new Rectangle(90, 220, 20, 20), MenuGlyph.Max);
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new ControlPaintForm());
        }

    }
}


           
          


Subclass Panel

   
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

public class ScrollingText : System.Windows.Forms.Panel {
    Font textFont = new Font("Times New Roman", 24);

    public ScrollingText() {
        InitializeComponent();
    }

    private void ScrollingText_Paint(object sender, PaintEventArgs e) {
        Graphics g = e.Graphics;
        g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
        g.DrawString("Hello, World", textFont, Brushes.Black, 40, 40);
        g.DrawString("Hello, World", textFont, Brushes.Red, 40, 240);
        g.DrawString("Hello, World", textFont, Brushes.Blue, 350, 40);
        g.DrawString("Hello, World", textFont, Brushes.Green, 350, 240);
    }
    private void InitializeComponent() {
        this.SuspendLayout();
        this.AutoScroll = true;
        this.AutoScrollMinSize = new System.Drawing.Size(600, 400);
        this.BackColor = System.Drawing.SystemColors.Window;
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.ScrollingText_Paint);
        this.ResumeLayout(false);
    }
}
public class Form1 : Form {
    public Form1() {
        InitializeComponent();
    }
    private void InitializeComponent() {
        this.scrollingText1 = new ScrollingText();
        this.SuspendLayout();
        this.scrollingText1.AutoScroll = true;
        this.scrollingText1.AutoScrollMinSize = new System.Drawing.Size(600, 400);
        this.scrollingText1.BackColor = System.Drawing.SystemColors.Window;
        this.scrollingText1.Location = new System.Drawing.Point(13, 13);
        this.scrollingText1.Size = new System.Drawing.Size(267, 243);
        this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 268);
        this.Controls.Add(this.scrollingText1);
        this.ResumeLayout(false);
    }
    private ScrollingText scrollingText1;
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}

    


Panel and form dock pad


   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
  private System.Windows.Forms.GroupBox GroupBox1;
  private System.Windows.Forms.Button cmdUpdate;
  private System.Windows.Forms.NumericUpDown udDockPaddingForm;
  private System.Windows.Forms.NumericUpDown udDockPaddingPanel;
  private System.Windows.Forms.ComboBox lstDockPanel;
  private System.Windows.Forms.Label Label3;
  private System.Windows.Forms.Label Label4;
  private System.Windows.Forms.ComboBox lstDockTextBox;
  private System.Windows.Forms.Label Label2;
  private System.Windows.Forms.Label Label1;
  private System.Windows.Forms.Panel pnlDock;
  private System.Windows.Forms.TextBox txtDock;

  public Form1() {
        InitializeComponent();
        lstDockPanel.Items.AddRange(Enum.GetNames(Dock.GetType()));
      lstDockTextBox.Items.AddRange(Enum.GetNames(Dock.GetType()));

      lstDockPanel.Text = Enum.GetName(Dock.GetType(), pnlDock.Dock);
      lstDockTextBox.Text = Enum.GetName(Dock.GetType(), lstDockTextBox.Dock);

  }
  private void cmdUpdate_Click(object sender, EventArgs e)
  {
    this.DockPadding.All = (int)udDockPaddingForm.Value;
    pnlDock.DockPadding.All = (int)udDockPaddingPanel.Value;

    TypeConverter converter;
    converter = TypeDescriptor.GetConverter(Dock.GetType());

    pnlDock.Dock = (DockStyle)converter.ConvertFromString(lstDockPanel.Text);
    txtDock.Dock = (DockStyle)converter.ConvertFromString(lstDockTextBox.Text);

  }

  private void InitializeComponent()
  {
    this.GroupBox1 = new System.Windows.Forms.GroupBox();
    this.cmdUpdate = new System.Windows.Forms.Button();
    this.udDockPaddingForm = new System.Windows.Forms.NumericUpDown();
    this.udDockPaddingPanel = new System.Windows.Forms.NumericUpDown();
    this.lstDockPanel = new System.Windows.Forms.ComboBox();
    this.Label3 = new System.Windows.Forms.Label();
    this.Label4 = new System.Windows.Forms.Label();
    this.lstDockTextBox = new System.Windows.Forms.ComboBox();
    this.Label2 = new System.Windows.Forms.Label();
    this.Label1 = new System.Windows.Forms.Label();
    this.pnlDock = new System.Windows.Forms.Panel();
    this.txtDock = new System.Windows.Forms.TextBox();
    this.GroupBox1.SuspendLayout();
    ((System.ComponentModel.ISupportInitialize)(this.udDockPaddingForm)).BeginInit();
    ((System.ComponentModel.ISupportInitialize)(this.udDockPaddingPanel)).BeginInit();
    this.pnlDock.SuspendLayout();
    this.SuspendLayout();
    // 
    // GroupBox1
    // 
    this.GroupBox1.Controls.Add(this.cmdUpdate);
    this.GroupBox1.Controls.Add(this.udDockPaddingForm);
    this.GroupBox1.Controls.Add(this.udDockPaddingPanel);
    this.GroupBox1.Controls.Add(this.lstDockPanel);
    this.GroupBox1.Controls.Add(this.Label3);
    this.GroupBox1.Controls.Add(this.Label4);
    this.GroupBox1.Controls.Add(this.lstDockTextBox);
    this.GroupBox1.Controls.Add(this.Label2);
    this.GroupBox1.Controls.Add(this.Label1);
    this.GroupBox1.Location = new System.Drawing.Point(202, 20);
    this.GroupBox1.Name = "GroupBox1";
    this.GroupBox1.Size = new System.Drawing.Size(284, 224);
    this.GroupBox1.TabIndex = 14;
    this.GroupBox1.TabStop = false;
    this.GroupBox1.Text = "Configure";
    // 
    // cmdUpdate
    // 
    this.cmdUpdate.Location = new System.Drawing.Point(160, 180);
    this.cmdUpdate.Name = "cmdUpdate";
    this.cmdUpdate.Size = new System.Drawing.Size(84, 24);
    this.cmdUpdate.TabIndex = 10;
    this.cmdUpdate.Text = "Update";
    this.cmdUpdate.Click += new System.EventHandler(this.cmdUpdate_Click);
    // 
    // udDockPaddingForm
    // 
    this.udDockPaddingForm.Increment = new decimal(new int[] {
        5,
        0,
        0,
        0});
    this.udDockPaddingForm.Location = new System.Drawing.Point(160, 32);
    this.udDockPaddingForm.Name = "udDockPaddingForm";
    this.udDockPaddingForm.Size = new System.Drawing.Size(52, 21);
    this.udDockPaddingForm.TabIndex = 4;
    // 
    // udDockPaddingPanel
    // 
    this.udDockPaddingPanel.Increment = new decimal(new int[] {
        5,
        0,
        0,
        0});
    this.udDockPaddingPanel.Location = new System.Drawing.Point(160, 56);
    this.udDockPaddingPanel.Name = "udDockPaddingPanel";
    this.udDockPaddingPanel.Size = new System.Drawing.Size(52, 21);
    this.udDockPaddingPanel.TabIndex = 5;
    this.udDockPaddingPanel.Value = new decimal(new int[] {
        20,
        0,
        0,
        0});
    // 
    // lstDockPanel
    // 
    this.lstDockPanel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    this.lstDockPanel.FormattingEnabled = true;
    this.lstDockPanel.Location = new System.Drawing.Point(156, 100);
    this.lstDockPanel.Name = "lstDockPanel";
    this.lstDockPanel.Size = new System.Drawing.Size(92, 21);
    this.lstDockPanel.TabIndex = 8;
    // 
    // Label3
    // 
    this.Label3.Location = new System.Drawing.Point(16, 104);
    this.Label3.Name = "Label3";
    this.Label3.Size = new System.Drawing.Size(136, 20);
    this.Label3.TabIndex = 6;
    this.Label3.Text = "Dock Panel To:";
    // 
    // Label4
    // 
    this.Label4.Location = new System.Drawing.Point(16, 128);
    this.Label4.Name = "Label4";
    this.Label4.Size = new System.Drawing.Size(136, 20);
    this.Label4.TabIndex = 7;
    this.Label4.Text = "Dock TextBox To:";
    // 
    // lstDockTextBox
    // 
    this.lstDockTextBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    this.lstDockTextBox.FormattingEnabled = true;
    this.lstDockTextBox.Location = new System.Drawing.Point(156, 124);
    this.lstDockTextBox.Name = "lstDockTextBox";
    this.lstDockTextBox.Size = new System.Drawing.Size(92, 21);
    this.lstDockTextBox.TabIndex = 9;
    // 
    // Label2
    // 
    this.Label2.Location = new System.Drawing.Point(16, 60);
    this.Label2.Name = "Label2";
    this.Label2.Size = new System.Drawing.Size(136, 20);
    this.Label2.TabIndex = 3;
    this.Label2.Text = "Panel&#039;s DockPadding:";
    // 
    // Label1
    // 
    this.Label1.Location = new System.Drawing.Point(16, 36);
    this.Label1.Name = "Label1";
    this.Label1.Size = new System.Drawing.Size(136, 20);
    this.Label1.TabIndex = 2;
    this.Label1.Text = "Form&#039;s DockPadding:";
    // 
    // pnlDock
    // 
    this.pnlDock.Controls.Add(this.txtDock);
    this.pnlDock.Dock = System.Windows.Forms.DockStyle.Left;
    this.pnlDock.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.pnlDock.Location = new System.Drawing.Point(0, 0);
    this.pnlDock.Name = "pnlDock";
    this.pnlDock.Padding = new System.Windows.Forms.Padding(20);
    this.pnlDock.Size = new System.Drawing.Size(224, 314);
    this.pnlDock.TabIndex = 13;
    // 
    // txtDock
    // 
    this.txtDock.Dock = System.Windows.Forms.DockStyle.Left;
    this.txtDock.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.txtDock.Location = new System.Drawing.Point(20, 20);
    this.txtDock.Multiline = true;
    this.txtDock.Name = "txtDock";
    this.txtDock.Size = new System.Drawing.Size(108, 274);
    this.txtDock.TabIndex = 0;
    this.txtDock.Text = "This is a TextBox.";
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(497, 314);
    this.Controls.Add(this.GroupBox1);
    this.Controls.Add(this.pnlDock);
    this.Text = "Docking At Work";
    this.GroupBox1.ResumeLayout(false);
    ((System.ComponentModel.ISupportInitialize)(this.udDockPaddingForm)).EndInit();
    ((System.ComponentModel.ISupportInitialize)(this.udDockPaddingPanel)).EndInit();
    this.pnlDock.ResumeLayout(false);
    this.pnlDock.PerformLayout();
    this.ResumeLayout(false);
  }


  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}



           
          


Use PageSetupDialog

   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

public class Form1 : Form {
    private Font mainTextFont = new Font("Times New Roman", 14);
    private Font subTextFont = new Font("Times New Roman", 12);
    private PageSettings storedPageSettings;

    public Form1() {
        InitializeComponent();
    }

    private void PaintDocument(Graphics g) {
        g.PageUnit = GraphicsUnit.Point;
        g.DrawString("Simple Printing Sample",
                     this.mainTextFont,
                     Brushes.Black,
                     new Rectangle(10, 20, 180, 30));
        g.DrawRectangle(Pens.Blue, new Rectangle(new Point(10, 100), new Size(100, 50)));
    }

    private void Form1_Paint(object sender, PaintEventArgs e) {
        Graphics g = e.Graphics;
        PaintDocument(g);
    }

    private void menuFilePageSetup_Click(object sender, EventArgs e) {
        try {
            PageSetupDialog psDlg = new PageSetupDialog();
            if (this.storedPageSettings == null)
                this.storedPageSettings = new PageSettings();
            psDlg.PageSettings = this.storedPageSettings;
            psDlg.ShowDialog();
        } catch (Exception ex) {
            MessageBox.Show(ex.Message);
        }
    }

    protected void PrintPageEventHandler(Object obj, PrintPageEventArgs ev) {
        Graphics g = ev.Graphics;
        PaintDocument(g);
        ev.HasMorePages = false;
    }

    private void menuFilePrint_Click(object sender, EventArgs e) {
        try {
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(this.PrintPageEventHandler);

            if (this.storedPageSettings != null)
                pd.DefaultPageSettings = this.storedPageSettings;
            PrintDialog dlg = new PrintDialog();
            dlg.Document = pd;
            DialogResult result = dlg.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
                pd.Print();
        } catch (Exception ex) {
            MessageBox.Show(ex.Message);
        }
    }

    private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e) {
        try {
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(this.PrintPageEventHandler);

            if (this.storedPageSettings != null)
                pd.DefaultPageSettings = this.storedPageSettings;
            PrintPreviewDialog dlg = new PrintPreviewDialog();
            dlg.Document = pd;
            dlg.ShowDialog();
        } catch (Exception ex) {
            MessageBox.Show(ex.Message);
        }
    }
    private void InitializeComponent() {
        this.menuStrip1 = new System.Windows.Forms.MenuStrip();
        this.menuFilePrintPreview = new System.Windows.Forms.ToolStripMenuItem();
        this.menuFilePageSetup = new System.Windows.Forms.ToolStripMenuItem();
        this.printPreviewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.menuFilePrint = new System.Windows.Forms.ToolStripMenuItem();
        this.menuStrip1.SuspendLayout();
        this.SuspendLayout();
        this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.menuFilePrintPreview});
        this.menuStrip1.Location = new System.Drawing.Point(0, 0);
        this.menuStrip1.Size = new System.Drawing.Size(292, 25);
        this.menuStrip1.Text = "menuStrip1";
        this.menuFilePrintPreview.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.menuFilePageSetup,
            this.printPreviewToolStripMenuItem,
            this.menuFilePrint});
        this.menuFilePrintPreview.Name = "menuFilePrintPreview";
        this.menuFilePrintPreview.Text = "File";
        this.menuFilePageSetup.Name = "menuFilePageSetup";
        this.menuFilePageSetup.Text = "Page Setup";
        this.menuFilePageSetup.Click += new System.EventHandler(this.menuFilePageSetup_Click);
        this.printPreviewToolStripMenuItem.Name = "printPreviewToolStripMenuItem";
        this.printPreviewToolStripMenuItem.Text = "Print Preview";
        this.printPreviewToolStripMenuItem.Click += new System.EventHandler(this.printPreviewToolStripMenuItem_Click);
        this.menuFilePrint.Name = "menuFilePrint";
        this.menuFilePrint.Text = "Print";
        this.menuFilePrint.Click += new System.EventHandler(this.menuFilePrint_Click);
        this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.SystemColors.Window;
        this.ClientSize = new System.Drawing.Size(292, 268);
        this.Controls.Add(this.menuStrip1);
        this.MainMenuStrip = this.menuStrip1;
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
        this.menuStrip1.ResumeLayout(false);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    private System.Windows.Forms.MenuStrip menuStrip1;
    private System.Windows.Forms.ToolStripMenuItem menuFilePrintPreview;
    private System.Windows.Forms.ToolStripMenuItem menuFilePageSetup;
    private System.Windows.Forms.ToolStripMenuItem printPreviewToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem menuFilePrint;
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}