Hi Guys
NP128 AddRange()
In some program without AddRange() method, button won’t appear on the Form. But in some program without AddRange() method, button appears on the Form. Actually what is the function of the AddRange(). Please explain.
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1});
Thank you
Program with AddRange()
namespace _9_WindowCreatedWithIDE
{
public class Form1 : System.Windows.Forms.Form
{
private Button button1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
// button1
this.button1.Location = new System.Drawing.Point(80, 64);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Press Me";
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
//this.Controls.Add(this.button1);
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1 });
this.Name = "Form1";
this.Text = "My IDE Form";
this.ResumeLayout(false);
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
}
}
Program without AddRange()
namespace _10_WindowCreatedWithIDE
{
public class Form1 : System.Windows.Forms.Form
{
private Button button1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
// button1
this.button1.Location = new System.Drawing.Point(80, 64);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Press Me";
this.button1.Click += new System.EventHandler(this.button1_Click);
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "My IDE Form";
this.ResumeLayout(false);
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Thank you");
}
}
}