Load image to RadioButton


   


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.RadioButton radioButton1;

  public Form1() {
        InitializeComponent();
  }

    private void InitializeComponent()
    {
        this.radioButton1 = new System.Windows.Forms.RadioButton();
        this.SuspendLayout();

        this.radioButton1.Image = new Bitmap("winter.jpg");
        this.radioButton1.Location = new System.Drawing.Point(12, 195);
        this.radioButton1.Name = "radioButton1";
        this.radioButton1.Size = new System.Drawing.Size(224, 47);
        this.radioButton1.TabIndex = 3;
        this.radioButton1.TabStop = true;
        this.radioButton1.Text = "radioButton1";
        this.radioButton1.UseVisualStyleBackColor = true;
  
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(299, 271);

        this.Controls.Add(this.radioButton1);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "ImagesInCommonControls";
        this.Text = "ImagesInCommonControls";
        this.ResumeLayout(false);

    }

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

}


           
          


Directory tree and property grid



   

/*
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)

ProgressBar Host


   

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

Publisher: Apress
ISBN: 1590590457
*/

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

namespace ProgressBarHost
{
    /// <summary>
    /// Summary description for ProgressBarHost.
    /// </summary>
    public class ProgressBarHost : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Timer tmrIncrementBar;
        private System.Windows.Forms.Button cmdStart;
        private Progress status;
        private System.ComponentModel.IContainer components;

        public ProgressBarHost()
        {
            //
            // 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.components = new System.ComponentModel.Container();
            this.status = new Progress();
            this.tmrIncrementBar = new System.Windows.Forms.Timer(this.components);
            this.cmdStart = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // status
            // 
            this.status.Location = new System.Drawing.Point(12, 8);
            this.status.Name = "status";
            this.status.Size = new System.Drawing.Size(272, 88);
            this.status.TabIndex = 0;
            // 
            // tmrIncrementBar
            // 
            this.tmrIncrementBar.Interval = 1000;
            this.tmrIncrementBar.Tick += new System.EventHandler(this.tmrIncrementBar_Tick);
            // 
            // cmdStart
            // 
            this.cmdStart.Location = new System.Drawing.Point(88, 152);
            this.cmdStart.Name = "cmdStart";
            this.cmdStart.Size = new System.Drawing.Size(92, 24);
            this.cmdStart.TabIndex = 1;
            this.cmdStart.Text = "Start";
            this.cmdStart.Click += new System.EventHandler(this.cmdStart_Click);
            // 
            // ProgressBarHost
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(292, 194);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.cmdStart,
                                                                          this.status});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "ProgressBarHost";
            this.Text = "ProgressBarHost";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new ProgressBarHost());
        }

        private void tmrIncrementBar_Tick(object sender, System.EventArgs e)
        {
            status.PerformStep();
            if (status.Maximum == status.Value)
            {
                tmrIncrementBar.Enabled = false;
            }

        }

        private void cmdStart_Click(object sender, System.EventArgs e)
        {
            tmrIncrementBar.Enabled = false;

            status.Value = 0;
            status.Maximum = 20;
            status.Step = 1;

            tmrIncrementBar.Enabled = true;

        }

    }
    /// <summary>
    /// Summary description for Progress.
    /// </summary>
    public class Progress : System.Windows.Forms.UserControl
    {
        internal System.Windows.Forms.Label lblProgress;
        internal System.Windows.Forms.ProgressBar Bar;
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Progress()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // TODO: Add any initialization after the InitForm 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 Component 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.lblProgress = new System.Windows.Forms.Label();
            this.Bar = new System.Windows.Forms.ProgressBar();
            this.SuspendLayout();
            // 
            // lblProgress
            // 
            this.lblProgress.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.lblProgress.Location = new System.Drawing.Point(5, 46);
            this.lblProgress.Name = "lblProgress";
            this.lblProgress.Size = new System.Drawing.Size(152, 16);
            this.lblProgress.TabIndex = 3;
            this.lblProgress.Text = "0% Done";
            this.lblProgress.TextAlign = System.Drawing.ContentAlignment.TopCenter;
            // 
            // Bar
            // 
            this.Bar.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.Bar.Location = new System.Drawing.Point(5, 6);
            this.Bar.Name = "Bar";
            this.Bar.Size = new System.Drawing.Size(154, 32);
            this.Bar.TabIndex = 2;
            // 
            // Progress
            // 
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.lblProgress,
                                                                          this.Bar});
            this.Name = "Progress";
            this.Size = new System.Drawing.Size(164, 68);
            this.ResumeLayout(false);

        }
        #endregion
        
        [Description("The current value (between 0 and Maximum) which sets the position of the progress bar"), 
        Category("Behavior"), DefaultValue(0)]
        public int Value
        {
            get
            {
                return Bar.Value;
            }
            set
            {
                Bar.Value = value;
                UpdateLabel();
            }
        }

        public int Maximum
        {
            get
            {
                return Bar.Maximum;
            }
            set
            {
                Bar.Maximum = value;
            }
        }

        public int Step
        {
            get
            {
                return Bar.Step;
            }
            set
            {
                Bar.Step = value;
            }
        }

        public void PerformStep()
        {
            Bar.PerformStep();
            UpdateLabel();
        }

        private void UpdateLabel()
        {
            lblProgress.Text = (Math.Round((decimal)(Bar.Value * 100) /
                Bar.Maximum)).ToString();
            lblProgress.Text += "% Done";
        }
    }



}


           
          


ProgressBar in C#


   

// I am trying to use Class ProgressBar in C#
// Editor Used : Antechinus http://www.c-point.com
// Dt. 9th Jan. 2001 
// ... Special thanks Saurabh for help &amp; guidance ... Thanks! someday i would 
//       do the way you do.... programming
// ... thanks Mahesh for loading my codes. Your site rules!
// ... thanks to you for reading it you know better who you are 🙂
// if you have any comments or doubts or whatever please don&#039;t 
// hesitate to e-mail me.

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

    /// <summary>
    ///    Summary description for Win32Form2.
    /// </summary>
    public class Win32Form2 : System.Windows.Forms.Form {

        /// <summary>
        ///    Required by the Win Forms designer
        /// </summary>
        private System.ComponentModel.Container components;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.ProgressBar progressBar1;

        public Win32Form2() {
            // Required for Win Form Designer support
            InitializeComponent();
        }

        /// <summary>
        ///    The main entry point for the application.
        /// </summary>
        public static void Main(string[] args) {
            Application.Run(new Win32Form2());
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with an editor
        /// </summary>
        private void InitializeComponent() {
            this.components = new System.ComponentModel.Container();
            this.label1 = new System.Windows.Forms.Label();
            this.progressBar1 = new System.Windows.Forms.ProgressBar();
            this.button1 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            
            //@design this.TrayHeight = 0;
            //@design this.TrayLargeIcon = false;
            //@design this.TrayAutoArrange = true;
            label1.Location = new System.Drawing.Point(32, 40);
            label1.Text = "Progress Value";
            label1.Size = new System.Drawing.Size(88, 24);
            label1.TabIndex = 2;
            
            progressBar1.Maximum = 10;
            progressBar1.Location = new System.Drawing.Point(8, 312);
            progressBar1.Minimum = 0;
            progressBar1.TabIndex = 0;
            progressBar1.Value = 0;
    
            //We have calculated the excat size which will result in only 20 boxes to be drawn
            
            progressBar1.Size = new System.Drawing.Size(520, 40);
            progressBar1.Step = 1;
            
            button1.Location = new System.Drawing.Point(152, 168);
            button1.Size = new System.Drawing.Size(144, 48);
            button1.TabIndex = 1;
            button1.Text = "button1";
            button1.Click += new System.EventHandler(button1_Click);
            
            textBox1.Location = new System.Drawing.Point(136, 40);
            textBox1.Text = "0";
            textBox1.TabIndex = 3;
            textBox1.Size = new System.Drawing.Size(184, 20);
            this.Text = "Win32Form2";
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(616, 393);
            this.Click += new System.EventHandler(Win32Form2_Click);
            
            this.Controls.Add(textBox1);
            this.Controls.Add(label1);
            this.Controls.Add(button1);
            this.Controls.Add(progressBar1);
        }

        protected void button1_Click(object sender, System.EventArgs e) {
        
            //this checking is automatically done as stated in the Ref Documentation 
            //but it does not work , BUGssssss 
            //so we have to do it shhhhh .... 
            if (progressBar1.Value == progressBar1.Maximum){
                progressBar1.Value =  progressBar1.Minimum;
            }
            progressBar1.PerformStep();
            textBox1.Text=progressBar1.Value.ToString() ; // Displays the values of progressbar in textbox
    
        }
        protected void Win32Form2_Click(object sender, System.EventArgs e) {
        }
    }



           
          


PrinterName, IsValid printer

   
 

using System;
using System.Drawing.Printing;

class MainClass {
    static void Main(string[] args) {
        foreach (string printerName in PrinterSettings.InstalledPrinters) {
            Console.WriteLine("Printer: {0}", printerName);

            PrinterSettings printer = new PrinterSettings();
            printer.PrinterName = printerName;
            Console.WriteLine(printer.IsValid);
        }
    }
}

    


PrinterResolutions

   
 


using System;
using System.Drawing.Printing;

class MainClass {
    static void Main(string[] args) {
        foreach (string printerName in PrinterSettings.InstalledPrinters) {
            Console.WriteLine("Printer: {0}", printerName);

            PrinterSettings printer = new PrinterSettings();
            printer.PrinterName = printerName;
            if (printer.IsValid) {
                Console.WriteLine("Supported Resolutions:");
                foreach (PrinterResolution resolution in printer.PrinterResolutions) {
                    Console.WriteLine("  {0}", resolution);
                }
            }
        }
    }
}