PART II
C h a p t e r 2 6 :
U s e S y s t e m . W i n d o w s . F o r m s
853
the
Controls
property, which is inherited from the
Control
class. The
Add( )
method is
defined like this:
public virtual void Add(Control
cntl
)
Here,
cntl
is the control being added. Once a control has been added to a form, it will be
displayed when the form is displayed.
A Simple Button Example
The following program adds a button to the skeleton shown earlier. At this time, the button
does not do anything, but it is present in the form and can be clicked.
// Add a Button.
using System;
using System.Windows.Forms;
using System.Drawing;
class ButtonForm : Form {
Button MyButton;
public ButtonForm() {
Text = "Using a Button";
MyButton = new Button();
MyButton.Text = "Press Here";
MyButton.Location = new Point(100, 200);
Controls.Add(MyButton);
}
[STAThread]
static void Main() {
ButtonForm skel = new ButtonForm();
Application.EnableVisualStyles();
Application.Run(skel);
}
}
This program creates a class called
Do'stlaringiz bilan baham: |