Как я располагаю все средства управления в панели или форме СРАЗУ??? c# [дубликат]

Я видел несколько соглашений о присвоении имен для потоков в.NET.

Некоторые предпочитают использовать 't' в начале имени (напр. Поток tMain ), но я не думаю, что он имеет любое действительное значение. Вместо этого, почему не только используют простые описательные имена (переменные строки) такой как HouseKeeping, Планировщик и так далее.

11
задан Community 23 May 2017 в 10:30
поделиться

4 ответа

Both the Panel and the Form class have a Controls collection property, which has a Clear() method...

MyPanel.Controls.Clear(); 

or

MyForm.Controls.Clear();

But Clear() doesn't call dispose() (All it does is remove he control from the collection), so what you need to do is

   List<Control> ctrls = new List<Control>(MyPanel.Controls);
   MyPanel.Controls.Clear();  
   foreach(Control c in ctrls )
      c.Dispose();

You need to create a separate list of the references because Dispose also will remove the control from the collection, changing the index and messing up the foreach...

34
ответ дан 3 December 2019 в 01:33
поделиться

I don't believe there is a way to do this all at once. You can just iterate through the child controls and call each of their dispose methods one at a time:

foreach(var control in this.Controls)
{
   control.Dispose();
}
3
ответ дан 3 December 2019 в 01:33
поделиться

You don't give much detail as to why.

This happens in the Dispose override method of the form (in form.designer.cs). It looks like this:

protected override void Dispose(bool disposing)
{
    if (disposing && (components != null))
    {
        components.Dispose();
    }

    base.Dispose(disposing);
}
2
ответ дан 3 December 2019 в 01:33
поделиться

You didn't share if this were ASP.Net or Winforms. If the latter, you can do well enough by first calling SuspendLayout() on the panel. Then, when finished, call ResumeLayout().

0
ответ дан 3 December 2019 в 01:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: