Form.ControlCollection.Add(Control) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee voegt u een besturingselement toe aan het formulier.
public:
override void Add(System::Windows::Forms::Control ^ value);
public override void Add(System.Windows.Forms.Control value);
public override void Add(System.Windows.Forms.Control? value);
override this.Add : System.Windows.Forms.Control -> unit
Public Overrides Sub Add (value As Control)
Parameters
Uitzonderingen
Er kunnen geen besturingselementen aan een bovenliggend MDI-formulier (MDI) worden toegevoegd.
Voorbeelden
In het volgende codevoorbeeld wordt een TextBox en Label besturingselement toegevoegd aan de verzameling besturingselementen van een formulier. Voor het voorbeeld moet een formulier zijn gemaakt en benoemd Form1.
public:
void AddMyControls()
{
TextBox^ textBox1 = gcnew TextBox;
Label^ label1 = gcnew Label;
// Initialize the controls and their bounds.
label1->Text = "First Name";
label1->Location = Point( 48, 48 );
label1->Size = System::Drawing::Size( 104, 16 );
textBox1->Text = "";
textBox1->Location = Point(48,64);
textBox1->Size = System::Drawing::Size( 104, 16 );
// Add the TextBox control to the form's control collection.
Controls->Add( textBox1 );
// Add the Label control to the form's control collection.
Controls->Add( label1 );
}
public void AddMyControls()
{
TextBox textBox1 = new TextBox();
Label label1 = new Label();
// Initialize the controls and their bounds.
label1.Text = "First Name";
label1.Location = new Point(48,48);
label1.Size = new Size (104, 16);
textBox1.Text = "";
textBox1.Location = new Point(48, 64);
textBox1.Size = new Size(104,16);
// Add the TextBox control to the form's control collection.
Controls.Add(textBox1);
// Add the Label control to the form's control collection.
Controls.Add(label1);
}
Public Sub AddMyControls()
Dim textBox1 As New TextBox()
Dim label1 As New Label()
' Initialize the controls and their bounds.
label1.Text = "First Name"
label1.Location = New Point(48, 48)
label1.Size = New Size(104, 16)
textBox1.Text = ""
textBox1.Location = New Point(48, 64)
textBox1.Size = New Size(104, 16)
' Add the TextBox control to the form's control collection.
Controls.Add(textBox1)
' Add the Label control to the form's control collection.
Controls.Add(label1)
End Sub
Opmerkingen
U kunt deze methode gebruiken om besturingselementen toe te voegen aan het formulier. Als u een groep al gemaakte besturingselementen aan het formulier wilt toevoegen, gebruikt u de Control.ControlCollection.AddRange methode van de Control.ControlCollection klasse.