C# Simplified, part 7: Working with WinForm Controls
(Page 1 of 6 )
In the previous article, we saw the fundamentals behind programming with .NET WinForms. In this article, we will examine the working of some of the important controls, which are used in normal windows applications, with the help of examples.
Working with Buttons
With the help of the Button control, you can perform some kind of activity on your application. For instance, clicking a button can generate a MessageBox or another Form. Further, you can sometimes add records to a database with the click of a button. The base class of Button is ButtonBase. This is also the base class for CheckBox and RadioButton controls. Listing 7.1 illustrates the usage of this important control:
Listing 7.1
001: // MyButton.cs
002: // -----------
003: using System;
004: using System.Drawing;
005: using System.Windows.Forms;
006:
007: public class MyButton:Form
008: {
009: Button b1 = new Button();
010:
011: MyButton()
012: {
013: b1.Text = "OK";
014: b1.BackColor = Color.Silver;
015: b1.Size = new Size(60,30);
016: b1.Location = new Point(50,40);
017: b1.FlatStyle = FlatStyle.Popup;
018: this.Controls.Add(b1);
019: this.Text = "Button Control Demo";
020: }
021:
022: public static void Main()
023: {
024: MyButton b = new MyButton();
025: Application.Run(b);
026: }
027: }
Output

Figure 7.1
You will note that nothing will happen if you click the buttons. This is because we didn't applied events. We will explore this concept in a later part of this article.
Next: Working with Checkboxes >>
More C# Articles
More By Anand Narayanaswamy