0
votes

C# Windows Forms: I was creating an test application using visual studio, i dragged a button on the form and created a an button_click event, when i debugged my application i found that "button" displayed on the form, even though i have not added my button to the form using "this.Controls.Add(button)". I have also checked the InitializeComponent() method under "filename.Designer.cs", there also "this.Controls.Add(button)" line was missing.

My doubt is: when debugged how the Control(button) automatically added to the form, without "this.Controls.Add(button)" instruction.

Thanks.

1
Are you sure you looked closely enough? I'm pretty sure there is a call to Controls.Add in InitializeComponents, otherwise it wouldn't work... - Thomas Levesque
Was it added to another container within the form? (e.g. a Panel) - JohnD
That's wired ,i had also a situation while working with Visual Studio 2010 and 2008 and changed the clock backward it Runn's the Application but without updates ,even if i wrote code it won't update it . - Rosmarine Popcorn
Sorry there was some mistake from my side, Ignore this post. Request the moderator to delete this post. Thanks - Vk Tt

1 Answers

2
votes

It does add it, it's in the "Windows Form Designer generated code" region.

#region Windows Form Designer generated code
// Removed to slim...
private void InitializeComponent()
{
    // Removed to slim...
    // 
    // Form1
    // 
    // Removed to slim...
    this.Controls.Add(this.button1);
    // Removed to slim...
}

#endregion