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

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. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / CSharp Tutorial » GUI Windows Forms » RadioButton 
22. 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());
    }
}

        
22. 11. RadioButton
22. 11. 1. RadioButton Click EventRadioButton Click Event
22. 11. 2. Put RadioButton to panel groupPut RadioButton to panel group
22. 11. 3. Set DialogResult.OK/DialogResult.Cancel to OK/Cancel buttonSet DialogResult.OK/DialogResult.Cancel to OK/Cancel button
22. 11. 4. Use RadioButton to control ListBox selection modeUse RadioButton to control ListBox selection mode
w_w__w_._j__a___v_a2_s___.___c__o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.