Question

Status:Closed    Asked:Jul 22, 2010 - 04:16 AM

wanted to add many radio buttons in windows application form in c#

hi
i am preparing question pool of multiple choice questions ,for that case i need to add many radio buttons
suggest me


Add New Comment


 
Do you have the same question? Follow this Question
 

Answers

Hi kavyagannarapu,

As always with C# programming the first step in creating an application is to state which libraries arerequited and then to create a new class which extends the basic C# Windows form class:
using System;
using System.Windows.Forms;
using System.Drawing;
public class MainForm : Form {
The next thing to do is to define the components required in the form. In this case a panel and three radio will be required:
private Panel langPanel = new Panel();
private RadioButton radBritish = new RadioButton();
private RadioButton radFrench = new RadioButton();
private RadioButton radSpanish = new RadioButton();
The panel is required in order to group the radio buttons together. Radio buttons with the same parent (in this case the panel) always act as a single unit so that as one button is clicked all others in the group are unchecked automatically. Radio buttons with different parents (for example in more that one panel) will not interact with each other.
The programmer can then define their new class’s main and constructor functions:
public static void Main() {
Application.Run(new MainForm());
}
public MainForm() {
setUpRadioButtons ();
}
The class’s constructor function calls another function (setUpRadioButtons) and it’s this one that sets up the radio buttons and the other components that are to be used on the form.
Setting Up Radio Buttons with C#
At this point the components have been created but are not yet connected to the new form. The programmer must:
•State where the component is to be placed on the form
•Add the component to the form
The programm uses the “Location” property to define where the component should lie. In this example the panel has been placed in the top left of the form:
public void setUpRadioButtons () {
langPanel.Location = new Point(0,0);
The location has two coordinates in “x” and “y”. Increasing “x” will move a component to the right, andincreasing “y” will move it down the form. Another useful property is “AutoSize”. Setting “AutoSize” to true will mean that the height and width of a component will automatically vary according do its contents:
langPanel.AutoSize = true;
Radio buttons share many of the same properties as panels (such as “Location” and “AutoSize”):
radBritish.Location = new Point(0,0);
radBritish.AutoSize = true;
However, there are some additional properties for the programmer to use. The “Text” is used to place an appropriate message next to the radio button, and setting “Checked” to true for a radio button will make it the default one:
radBritish.Text = "English";
radBritish.Checked = true;
Each of the radio buttons is set in the same way (but only one should have “Checked” set to true):
radFrench.Location = new Point(radBritish.Width,0);
radFrench.AutoSize = true;
radFrench.Text = "French";
radSpanish.Location = new Point
(radBritish.Width + radFrench.Width,0);
radSpanish.AutoSize = true;
radSpanish.Text = "Spanish";
lblDay.Location = new Point(0,radBritish.Height);
lblDay.AutoSize = true;
And finally the programmer must add the components to the form:
langPanel.Controls.Add(radBritish);
langPanel.Controls.Add(radFrench);
langPanel.Controls.Add(radSpanish);
this.Controls.Add(langPanel);
}
If the form is compiled at this point then the application you will see three simple but effective radio buttons.


Add New Comment


 

Jul 23, 2010 - 04:04 AM

0
0
Report it

Hi kavyagannarapu,

Did my previous post help you at all ?


Add New Comment


 

Aug 09, 2010 - 02:24 AM

0
0
Report it


OTHER QUESTIONS NEEDING ANSWERS

How would you get your news articles on these newsfeed?
Is there any Se which has got more interesting features in tandem with its ma...
What're the most useful free web sites or free pc software for building resea...
What's the fastest method to get my weblog list from the main research engine...
So how exactly does search engine marketing work?
How do you make my website feature in a research engine?
Login   |   Register

Ask a question on Quomon


kavyagannarapu
504
1729
0 question
1 question
Knowledgeable, Contributor

 | Direct a question to this member
Suleman
1100
18
45 questions
0 question
Experienced, Knowledgeable, Contributor

 | Direct a question to this member
Urypomuer
170
3156
11 questions
0 question

 | Direct a question to this member
hiphop
135
3165
7 questions
0 question

 | Direct a question to this member
Quintin854
91
3192
5 questions
0 question

 | Direct a question to this member
Hee Huntington
83
3196
3 questions
0 question

 | Direct a question to this member