C#
  Home arrow C# arrow Page 3 - C# Simplified, part 7: Working with WinFor...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

C# Simplified, part 7: Working with WinForm Controls
By: Anand Narayanaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2005-06-14

    Table of Contents:
  • C# Simplified, part 7: Working with WinForm Controls
  • Working with Checkboxes
  • Working with RadioButtons
  • Working with Labels
  • Working with Combo boxes
  • Working with List boxes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    C# Simplified, part 7: Working with WinForm Controls - Working with RadioButtons


    (Page 3 of 6 )

    With RadioButtons, you can let your users select a single choice at a time, rather than a set of choices as seen in the previous session. Listing 7.3 demonstrates the usage of this control:

    Listing 7.3

    001: using System;
    002: using System.Drawing;
    003: using System.Windows.Forms;
    004:
    005: public class MyRadiobutton: Form
    006: {
    007:   RadioButton rad1 = new RadioButton();
    008:   RadioButton rad2 = new RadioButton();
    009:   GroupBox grp = new GroupBox();
    010:
    011:   MyRadiobutton()
    012:   {
    013:
    014:     rad1.Text = "Employed";
    015:     rad1.Location = new Point(20,20);
    016:
    017:     rad2.Text = "Unemployed";
    018:     rad2.Location = new Point(20,40);
    019:
    020:     grp.Location = new Point(20,20);
    021:     grp.Text = "Your Employment Status";
    022:     grp.BackColor = Color.Silver;
    023:
    024:     // radio buttons added to group box
    025:
    026:     grp.Controls.Add(this.rad1);
    027:     grp.Controls.Add(this.rad2);
    028:
    029:     // group box added to the form
    030:
    031:     this.Controls.Add(grp);
    032:     this.Text = "RadioButton Control Demo";
    033:   }
    034:
    035:
    036:   public static void Main()
    037:   {
    038:     MyRadiobutton myrad = new MyRadiobutton();
    039:     Application.Run(myrad);
    040:   }
    041: }

    From the above listing, you can see that RadioButtons are first added to a GroupBox. This is necessary, because otherwise you will not get the functionality of the RadioButton. If you have worked with Visual Basic 6.0, you will be able to infer that GroupBox is similar to Frames. After this process, the GroupBox instance is added to the Form. It is not necessary for you to add each and every RadioButton instance to the form.

    Output

    Figure 7.3

    More C# Articles
    More By Anand Narayanaswamy


     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT