RadioButton.Appearance : RadioButton « System.Windows.Forms « C# / C Sharp by API






RadioButton.Appearance

  

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace RadioButtonWithImg
{
  /// <summary>
  /// Summary description for RadioButtonWithImg.
  /// </summary>
  public class RadioButtonWithImg : System.Windows.Forms.Form
  {
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.RadioButton radioButton1;
    private System.Windows.Forms.RadioButton radioButton2;
    private System.Windows.Forms.RadioButton radioButton3;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public RadioButtonWithImg()
    {
      //
      // 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.groupBox1 = new System.Windows.Forms.GroupBox();
         this.radioButton3 = new System.Windows.Forms.RadioButton();
         this.radioButton2 = new System.Windows.Forms.RadioButton();
         this.radioButton1 = new System.Windows.Forms.RadioButton();
         this.groupBox1.SuspendLayout();
         this.SuspendLayout();
         // 
         // groupBox1
         // 
         this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                this.radioButton3,
                                                                                this.radioButton2,
                                                                                this.radioButton1});
         this.groupBox1.Location = new System.Drawing.Point(8, 16);
         this.groupBox1.Name = "groupBox1";
         this.groupBox1.Size = new System.Drawing.Size(160, 120);
         this.groupBox1.TabIndex = 1;
         this.groupBox1.TabStop = false;
         this.groupBox1.Text = "Group 1";
         // 
         // radioButton3
         // 
         this.radioButton3.Appearance = System.Windows.Forms.Appearance.Button;
         this.radioButton3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
         this.radioButton3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
         this.radioButton3.Location = new System.Drawing.Point(16, 88);
         this.radioButton3.Name = "radioButton3";
         this.radioButton3.Size = new System.Drawing.Size(120, 24);
         this.radioButton3.TabIndex = 2;
         this.radioButton3.Text = "Option3";
         // 
         // radioButton2
         // 
         this.radioButton2.Appearance = System.Windows.Forms.Appearance.Button;
         this.radioButton2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
         this.radioButton2.Location = new System.Drawing.Point(16, 56);
         this.radioButton2.Name = "radioButton2";
         this.radioButton2.Size = new System.Drawing.Size(120, 24);
         this.radioButton2.TabIndex = 1;
         this.radioButton2.Text = "Option2";
         this.radioButton2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
         // 
         // radioButton1
         // 
         this.radioButton1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
         this.radioButton1.Location = new System.Drawing.Point(16, 24);
         this.radioButton1.Name = "radioButton1";
         this.radioButton1.Size = new System.Drawing.Size(120, 24);
         this.radioButton1.TabIndex = 0;
         this.radioButton1.Text = "Option1";
         this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
         // 
         // RadioButton
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(184, 149);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.groupBox1});
         this.Name = "RadioButton";
         this.Text = "Radio Button";
         this.Load += new System.EventHandler(this.RadioButtonWithImg_Load);
         this.groupBox1.ResumeLayout(false);
         this.ResumeLayout(false);

      }
    #endregion

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

    private void RadioButtonWithImg_Load(object sender, System.EventArgs e)
    {
      // Select the Image for the button
      Image img = Image.FromFile("EYE.ICO");    
      // Assign the Image to the button
      radioButton1.Image = img ;
      // Align the image 
      radioButton1.ImageAlign = ContentAlignment.MiddleRight;

      // Select the Image for the button
      img = Image.FromFile("WRENCH.ICO");    
      // Assign the Image to the button
      radioButton2.Image = img ;
      // Align the image 
      radioButton2.ImageAlign = ContentAlignment.MiddleLeft;
    }

      private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
      {
         if (radioButton1.Checked)
            MessageBox.Show("Checked!");
         else
            MessageBox.Show("Not checked!");
      }
  }
}

   
    
  








Related examples in the same category

1.RadioButton.Checked
2.RadioButton.CheckedChanged
3.RadioButton.Image
4.RadioButton.ImageAlign