I have these two methods and as you can see it is just repeated code. How can I merge these into one method and pass an object type as a parameter?
private void addButton (string Text, Point Location, Size Size) { Button b = new Button();
b.Name = Text; b.Text = Text;
b.Location = Location; b.Size = Size;
this.Controls.Add(b); }
private void addLabel(string Text, Point Location, Size Size) { Label l = new Label();
l.Name = Text; l.Text = Text;
l.Location = Location; l.Size = Size;
this.Controls.Add(l); }
|
Thanks in advance. =)
Sam HobbsPosted Nov 11, 2010, 12:23 AM
Sam HobbsPosted Nov 11, 2010, 1:55 AM
Jason AkkermanPosted Nov 11, 2010, 12:46 AM
addControl("TEST", new Point(450, 10), new Size(100, 25), new Button());
private void addControl(string Text, Point Location, Size Size, Control C)
{
C.Name = Text;
C.Text = Text;
C.Location = Location;
C.Size = Size;
this.Controls.Add(C);
}
Manikavelu VelayuthamPosted Nov 11, 2010, 12:25 AM
{
Control ctl = new Control();
if (Isbutton!=true)
ctl = new Label();
else
ctl = new Button();
ctl.Name = Text;
ctl.Text = Text;
ctl.Location = Location;
ctl.Size = Size;
this.Controls.Add(ctl);
}