Вот код
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void ListFiles()
{
for (int i = 0; i < elemList.Count; i++)
{
Button b1 = new Button();
b1.Location = new System.Drawing.Point(this.ClientRectangle.Width / 2 - 125 / 2, this.ClientRectangle.Height / 2 - 32);
b1.Size = new Size(125, 32);
b1.TabIndex = 0;
b1.Text = "TEXT";
b1.UseVisualStyleBackColor = true;
UserControl1 cont = new UserControl1();
cont.Controls.Add(b1);
y += 85;
}
}
}
Цикл проходит как надо, но ничего не рисуется в контроле. В чем проблема? Если поместить код в UserControl(), то всё работает. Но мне нужно через отдельную функцию, чтобы только после определенных событий рисовало кнопку.