RadioButton Click Event : RadioButton « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » RadioButton 
23.11.1.RadioButton Click Event
RadioButton Click Event
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public partial class Form1 : Form
{
    string ticketClass;
    
    public Form1()
    {
        InitializeComponent();
    }

    private void okButton_Click(object sender, EventArgs e)
    {
        MessageBox.Show(ticketClass);
    }

    private void TicketTypeChanged(object sender, EventArgs e)
    {
        RadioButton button = (RadioButton)sender;
        if (button.Checked)
            ticketClass = button.Text;
    }
}
partial class Form1
{
    private void InitializeComponent()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.economyRadio = new System.Windows.Forms.RadioButton();
        this.premiumRadio = new System.Windows.Forms.RadioButton();
        this.businessRadio = new System.Windows.Forms.RadioButton();
        this.upperRadio = new System.Windows.Forms.RadioButton();
        this.firstRadio = new System.Windows.Forms.RadioButton();
        this.okButton = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(129);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(16813);
        this.label1.TabIndex = 0;
        this.label1.Text = "Choose the cabin class you require";
        // 
        // economyRadio
        // 
        this.economyRadio.AutoSize = true;
        this.economyRadio.Location = new System.Drawing.Point(4644);
        this.economyRadio.Name = "economyRadio";
        this.economyRadio.Size = new System.Drawing.Size(6517);
        this.economyRadio.TabIndex = 1;
        this.economyRadio.Text = "Economy";
        this.economyRadio.CheckedChanged += new System.EventHandler(this.TicketTypeChanged);
        // 
        // premiumRadio
        // 
        this.premiumRadio.AutoSize = true;
        this.premiumRadio.Location = new System.Drawing.Point(4668);
        this.premiumRadio.Name = "premiumRadio";
        this.premiumRadio.Size = new System.Drawing.Size(10817);
        this.premiumRadio.TabIndex = 2;
        this.premiumRadio.Text = "Premium Economy";
        this.premiumRadio.CheckedChanged += new System.EventHandler(this.TicketTypeChanged);
        // 
        // businessRadio
        // 
        this.businessRadio.AutoSize = true;
        this.businessRadio.Location = new System.Drawing.Point(4692);
        this.businessRadio.Name = "businessRadio";
        this.businessRadio.Size = new System.Drawing.Size(9017);
        this.businessRadio.TabIndex = 3;
        this.businessRadio.Text = "Business class";
        this.businessRadio.CheckedChanged += new System.EventHandler(this.TicketTypeChanged);
        // 
        // upperRadio
        // 
        this.upperRadio.AutoSize = true;
        this.upperRadio.Location = new System.Drawing.Point(46115);
        this.upperRadio.Name = "upperRadio";
        this.upperRadio.Size = new System.Drawing.Size(12317);
        this.upperRadio.TabIndex = 4;
        this.upperRadio.Text = "Upper Business Class";
        this.upperRadio.CheckedChanged += new System.EventHandler(this.TicketTypeChanged);
        // 
        // firstRadio
        // 
        this.firstRadio.AutoSize = true;
        this.firstRadio.Location = new System.Drawing.Point(46139);
        this.firstRadio.Name = "firstRadio";
        this.firstRadio.Size = new System.Drawing.Size(6717);
        this.firstRadio.TabIndex = 5;
        this.firstRadio.Text = "First class";
        this.firstRadio.CheckedChanged += new System.EventHandler(this.TicketTypeChanged);
        // 
        // okButton
        // 
        this.okButton.Location = new System.Drawing.Point(212194);
        this.okButton.Name = "okButton";
        this.okButton.Size = new System.Drawing.Size(7523);
        this.okButton.TabIndex = 6;
        this.okButton.Text = "OK";
        this.okButton.Click += new System.EventHandler(this.okButton_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(299229);
        this.Controls.Add(this.okButton);
        this.Controls.Add(this.firstRadio);
        this.Controls.Add(this.upperRadio);
        this.Controls.Add(this.businessRadio);
        this.Controls.Add(this.premiumRadio);
        this.Controls.Add(this.economyRadio);
        this.Controls.Add(this.label1);
        this.Name = "Form1";
        this.Text = "Flight Booker";
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.RadioButton economyRadio;
    private System.Windows.Forms.RadioButton premiumRadio;
    private System.Windows.Forms.RadioButton businessRadio;
    private System.Windows.Forms.RadioButton upperRadio;
    private System.Windows.Forms.RadioButton firstRadio;
    private System.Windows.Forms.Button okButton;
}
public class RadioButtonClickEvent
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}
23.11.RadioButton
23.11.1.RadioButton Click EventRadioButton Click Event
23.11.2.Put RadioButton to panel groupPut RadioButton to panel group
23.11.3.Set DialogResult.OK/DialogResult.Cancel to OK/Cancel buttonSet DialogResult.OK/DialogResult.Cancel to OK/Cancel button
23.11.4.Use RadioButton to control ListBox selection modeUse RadioButton to control ListBox selection mode
23.11.5.RadioButton Image
23.11.6.Color Radio Buttons
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.