У меня есть форма, и я хочу, чтобы при создании нового объекта объекта «SecondClass» я должен был создать собственную метку с разницей в 20 пикселей (разность координат) от других меток. Но результат: есть только первый ярлык показывает, как решить эту проблему?
public partial class AppForm : Form
{
public AppForm()
{
InitializeComponent();
}
private void AppForm_Load(object sender, EventArgs e)
{
SecondClass myFirstObject = new SecondClass("FirstLabel", this);
SecondClass mySecondObject = new SecondClass("SecondLabel", this);
SecondClass mythirdObject = new SecondClass("ThirdLabel", this);
}
}
public class SecondClass
{
public static int x_coordinate = 10;
private AppForm FormObject { get; set; }
private string LabelText { get; set; }
public SecondClass(string argLabelText, AppForm argFormObject)
{
x_coordinate = x_coordinate + 20;
FormObject = argFormObject;
LabelText = argLabelText;
DisplayInformation();
}
public void DisplayInformation()
{
Label myLabel = new Label();
myLabel.Text = LabelText;
myLabel.Location = new Point(x_coordinate , 90);
FormObject.Controls.Add(myLabel);
}
}