Concepts of Programming Languages

(Sean Pound) #1
14.7 Event Handling in C# 663

bold.Text = "Bold";
italic.Location = new Point(480, 0);
italic.Text = "Italics";
boldItalic.Location = new Point(610, 0);
boldItalic.Text = "Bold/Italics";


// Add the text and the radio buttons to the form
Controls.Add(text);
Controls.Add(plain);
Controls.Add(bold);
Controls.Add(italic);
Controls.Add(boldItalic);


// Register the event handler for the radio buttons
plain .CheckedChanged +=
new EventHandler(rb_CheckedChanged);
bold. CheckedChanged +=
new EventHandler(rb_CheckedChanged);
itali c.CheckedChanged +=
new EventHandler(rb_CheckedChanged);
boldI talic.CheckedChanged +=
new EventHandler(rb_CheckedChanged);
}


// The main method is where execution begins
static void Main() {
Application.EnableVisualStyles();
Appl ication.SetCompatibleTextRenderingDefault
(false);
Application.Run(new RadioB());
}


// The event handler


private void rb_CheckedChanged ( object o,
EventArgs e) {


// Determine which button is on and set the font
// accordingly
if (plain.Checked)
text.Font =
new Font( text.Font.Name, text.Font.Size,
FontStyle.Regular);
if (bold.Checked)
text.Font =

Free download pdf