Hello,
I'm trying to create a Button Class that will be used to create buttons on a form. This is the class I've created:
public class CreateButton : Button
{
public Button newButton;
private string _buttonName;
private Point _buttonLocation;
private Size _buttonSize;
public string ButtonName
{
get { return _buttonName; }
set {_buttonName = value; }
}
public Point ButtonLocation
{
get { return _buttonLocation; }
set { _buttonLocation = value; }
}
public Size ButtonSize
{
get { return _buttonSize; }
set { _buttonSize = value; }
}
public CreateButton(string btnName, Point btnLocation, Size btnSize)
{
ButtonName = btnName;
ButtonLocation = btnLocation;
ButtonSize = btnSize;
newButton = new Button();
newButton.Text = btnName;
newButton.Location = btnLocation;
newButton.Size = btnSize;
Controls.Add(newButton);
}
}
Then... in the main form where I want to create the buttons, I use the following code:
CreateButton btn0 = new CreateButton("Save", new Point(5, 5), new Size(40, 40));
Controls.Add(btn0);
The thing is that it actually creates two buttons, with the button I want to create inside another one. If I don't add the control no button will be created...
Can anyone please tell me what I'm doing wrong, because I don't really know what I'm doing here :/
Thank you.