RadioButton With Img

image_pdfimage_print



   

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


           
          


RadioButton.zip( 30 k)

Radio Group

image_pdfimage_print

/*
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 Peaks
{
///

/// Summary description for Peaks.
///

public class Peaks : 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;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.RadioButton radioButton5;
private System.Windows.Forms.RadioButton radioButton6;
private System.Windows.Forms.RadioButton radioButton7;
private System.Windows.Forms.RadioButton radioButton8;
private System.Windows.Forms.RadioButton radioButton9;
private System.Windows.Forms.RadioButton radioButton10;
private System.Windows.Forms.RadioButton radioButton11;
private System.Windows.Forms.RadioButton radioButton12;

Point[] pnts = { new Point(20, 90), new Point(55, 70),
new Point(80, 80), new Point(105, 40),
new Point(130, 90)};

///

/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Peaks()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.radioButton1.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton2.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton3.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton4.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton5.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton6.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton7.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton8.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton9.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton10.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton11.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
this.radioButton12.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);

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

///

/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///

/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton6 = new System.Windows.Forms.RadioButton();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.radioButton7 = new System.Windows.Forms.RadioButton();
this.radioButton9 = new System.Windows.Forms.RadioButton();
this.radioButton8 = new System.Windows.Forms.RadioButton();
this.radioButton10 = new System.Windows.Forms.RadioButton();
this.radioButton12 = new System.Windows.Forms.RadioButton();
this.radioButton11 = new System.Windows.Forms.RadioButton();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioButton1,
this.radioButton2,
this.radioButton3,
this.radioButton6,
this.radioButton5,
this.radioButton4,
this.radioButton7,
this.radioButton9,
this.radioButton8,
this.radioButton10,
this.radioButton12,
this.radioButton11});
this.groupBox1.Location = new System.Drawing.Point(200, 8);
this.groupBox1.Name = “groupBox1”;
this.groupBox1.Size = new System.Drawing.Size(304, 120);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = “Primitives”;
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(16, 24);
this.radioButton1.Name = “radioButton1”;
this.radioButton1.Size = new System.Drawing.Size(88, 16);
this.radioButton1.TabIndex = 0;
this.radioButton1.Text = “4xLine”;
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(112, 24);
this.radioButton2.Name = “radioButton2”;
this.radioButton2.Size = new System.Drawing.Size(56, 16);
this.radioButton2.TabIndex = 0;
this.radioButton2.Text = “Lines”;
//
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(184, 24);
this.radioButton3.Name = “radioButton3”;
this.radioButton3.Size = new System.Drawing.Size(80, 16);
this.radioButton3.TabIndex = 0;
this.radioButton3.Text = “Polygon”;
//
// radioButton6
//
this.radioButton6.Location = new System.Drawing.Point(184, 48);
this.radioButton6.Name = “radioButton6”;
this.radioButton6.Size = new System.Drawing.Size(80, 16);
this.radioButton6.TabIndex = 0;
this.radioButton6.Text = “Curve 1.1”;
//
// radioButton5
//
this.radioButton5.Location = new System.Drawing.Point(112, 48);
this.radioButton5.Name = “radioButton5”;
this.radioButton5.Size = new System.Drawing.Size(88, 16);
this.radioButton5.TabIndex = 0;
this.radioButton5.Text = “Curve 0.6”;
//
// radioButton4
//
this.radioButton4.Location = new System.Drawing.Point(16, 48);
this.radioButton4.Name = “radioButton4”;
this.radioButton4.Size = new System.Drawing.Size(88, 16);
this.radioButton4.TabIndex = 0;
this.radioButton4.Text = “Curve 0”;
//
// radioButton7
//
this.radioButton7.Location = new System.Drawing.Point(16, 72);
this.radioButton7.Name = “radioButton7”;
this.radioButton7.Size = new System.Drawing.Size(88, 16);
this.radioButton7.TabIndex = 0;
this.radioButton7.Text = “2xBezier”;
//
// radioButton9
//
this.radioButton9.Location = new System.Drawing.Point(184, 72);
this.radioButton9.Name = “radioButton9”;
this.radioButton9.Size = new System.Drawing.Size(112, 16);
this.radioButton9.TabIndex = 0;
this.radioButton9.Text = “ClosedCurve 1.1”;
//
// radioButton8
//
this.radioButton8.Location = new System.Drawing.Point(112, 72);
this.radioButton8.Name = “radioButton8”;
this.radioButton8.Size = new System.Drawing.Size(88, 16);
this.radioButton8.TabIndex = 0;
this.radioButton8.Text = “Beziers”;
//
// radioButton10
//
this.radioButton10.Location = new System.Drawing.Point(16, 96);
this.radioButton10.Name = “radioButton10”;
this.radioButton10.Size = new System.Drawing.Size(88, 16);
this.radioButton10.TabIndex = 0;
this.radioButton10.Text = “2xBezier”;
//
// radioButton12
//
this.radioButton12.Location = new System.Drawing.Point(184, 96);
this.radioButton12.Name = “radioButton12”;
this.radioButton12.Size = new System.Drawing.Size(88, 16);
this.radioButton12.TabIndex = 0;
this.radioButton12.Text = “Curve”;
//
// radioButton11
//
this.radioButton11.Location = new System.Drawing.Point(112, 96);
this.radioButton11.Name = “radioButton11”;
this.radioButton11.Size = new System.Drawing.Size(88, 16);
this.radioButton11.TabIndex = 0;
this.radioButton11.Text = “Beziers”;
//
// Peaks
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(504, 133);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox1});
this.Name = “Peaks”;
this.Text = “Two Peaks”;
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion

///

/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Peaks());
}
private void RBs_CheckedChanged(object sender, System.EventArgs e)
{
this.Refresh();
}
protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(this.BackColor);

if (this.radioButton1.Checked) Ex01_4xLine(g);
if (this.radioButton2.Checked) Ex02_Lines(g);
if (this.radioButton3.Checked) Ex03_Polygon(g);
if (this.radioButton4.Checked) Ex04_Curve0(g);
if (this.radioButton5.Checked) Ex05_Curve1(g);
if (this.radioButton6.Checked) Ex06_Curve2(g);
if (this.radioButton7.Checked) Ex07_2xBezier(g);
if (this.radioButton8.Checked) Ex08_Beziers(g);
if (this.radioButton9.Checked) Ex09_ClosedCurve(g);
if (this.radioButton10.Checked) Ex10_2xBezier_2(g);
if (this.radioButton11.Checked) Ex11_Beziers_2(g);
if (this.radioButton12.Checked) Ex11_Curve_2(g);

g.Dispose();
}
protected void Ex01_4xLine(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawLine(pn, 20, 90, 55, 70);
g.DrawLine(pn, 55, 70, 80, 80);
g.DrawLine(pn, 80, 80,105, 40);
g.DrawLine(pn,105, 40,130, 90);
}

protected void Ex02_Lines(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawLines(pn, pnts);
}
protected void Ex03_Polygon(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawPolygon(pn, pnts);
}
protected void Ex04_Curve0(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawCurve(pn, pnts, 0.0f);
}
protected void Ex05_Curve1(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawCurve(pn, pnts, 0.6f);
}
protected void Ex06_Curve2(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawCurve(pn, pnts, 1.1f);
}
protected void Ex07_2xBezier(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawBezier(pn, 20, 90, 50, 70, 60, 70, 80, 80);
g.DrawBezier(pn, 80, 80,100, 40,110, 40,130, 90);
}

protected void Ex08_Beziers(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
Point[] pnts = {new Point(20, 90), new Point(50, 70),
new Point(60, 70), new Point(80, 80),
new Point(100, 40), new Point(110, 40),
new Point(130, 90)};
g.DrawBeziers(pn, pnts);
}
protected void Ex09_ClosedCurve(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
Point[] pnts = {new Point( 20, 90), new Point( 55, 70),
new Point( 80, 80), new Point(105, 40),
new Point(130, 90)};
g.DrawClosedCurve(pn, pnts, 1.1f, System.Drawing.Drawing2D.FillMode.Winding);
}
protected void Ex10_2xBezier_2(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
g.DrawBezier(pn, 20, 90, 50, 70, 60, 70, 80, 80);
g.DrawBezier(pn, 80, 80,100,120,110,120,130, 90);
}
protected void Ex11_Beziers_2(Graphics g)
{
Pen pn = new Pen(Color.Blue, 2);
int[,] xy = { { 20, 90}, { 50, 70},
{ 60, 70}, { 80, 80},
{100,120}, {110,120},
{130, 90}};
int ii = xy.GetLength(0);
Point[] pnts = new Point[ii];
for(int i = 0; i < ii; i++) { pnts[i].X = xy[i, 0]; pnts[i].Y = xy[i, 1]; } g.DrawBeziers(pn, pnts); } protected void Ex11_Curve_2(Graphics g) { Pen pn = new Pen(Color.Blue, 2); Point[] pnts = {new Point( 20, 90), new Point( 55, 70), new Point( 80, 80), new Point(105,120), new Point(130, 90)}; g.DrawCurve(pn, pnts, 0.0f); } } } [/csharp]

Reading from a String Resource

image_pdfimage_print


   

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
   
public class MainForm
{
    public static void Main()
    {
        ResourceManager FormResources = new ResourceManager("StringTable", Assembly.GetExecutingAssembly());
        string          Message;
        
        Message = FormResources.GetString("Message");
        MessageBox.Show(Message);
    }
}
           
          


Reading resources

image_pdfimage_print

using System;
using System.Resources;
using System.Collections;

public class MainClass {
public static void DumpResources(string resName) {
ResourceReader reader = new ResourceReader(resName);
IDictionaryEnumerator en = reader.GetEnumerator();
while (en.MoveNext()) {
Console.WriteLine(“Resource Name: [{0}] = {1}”, en.Key, en.Value);
}
reader.Close();
}

public static void DumpAResource(string resName, string keyName) {
try {
ResourceManager rMgr = new ResourceManager(resName,
System.Reflection.Assembly.GetExecutingAssembly());
Console.WriteLine(“Resource: {0}”, rMgr.GetString(keyName));
} catch (Exception e) {
Console.WriteLine(“Exception creating manager {0}”, e);
return;
}
}

public static void Main(string[] args) {
for (int i = 0; i < args.Length; ++i) DumpAResource("English", args[i]); DumpResources("English1.resources"); } } [/csharp]

Check the key in a .resources file

image_pdfimage_print
   


using System;
using System.Resources;
using System.Collections;

public class MainClass {
    public static void DisplayGreeting(string resName) {
        try {
            ResourceReader reader = new ResourceReader(resName + ".resources");
            IDictionaryEnumerator dict = reader.GetEnumerator();
            while (dict.MoveNext()) {
                string s = (string)dict.Key;
                if (s == "Greeting")
                    Console.WriteLine("{0}", dict.Value);
            }
        } catch (Exception e) {
            Console.WriteLine("Exception creating manager {0}", e);
            return;
        }
    }

    public static void Main(string[] args) {
        DisplayGreeting(args[0]);
    }
}

           
          


Make a new *.resources file.

image_pdfimage_print
   


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


public class MainClass {
    public static void Main() {
        ResourceWriter rw = new ResourceWriter(@"C:myResources.resources");

        // Add 1 image and 1 string.
        rw.AddResource("happyDude", new Bitmap("happyDude.bmp"));
        rw.AddResource("welcomeString", "Hello new resource format!");
        rw.Generate();
        rw.Close();
    }
}