C# InvokeMember auf Control.Controls.Add?

1 Antwort

Vom Fragesteller als hilfreich ausgezeichnet

Das FlowLayoutPanel besitzt keinen Member namens "Controls.Add". Es gibt allerhöchstens ein Property Controls, welches aufrufbar wäre.

So eine Implementation dürfte klappen:

private void AddControl(Control parent, Control control)
{
  if (parent == null || control == null)
  {
    return;
  }

  if (InvokeRequired)
  {
    Invoke(AddControl, new object[] { parent, control });
    return;
  }

  parent.Controls.Add(control);
}
RANGObro 
Fragesteller
 03.12.2022, 13:09

Ja das hat geklappt. parent.Controls.Add(control); wird trotzdem im thread von parent ausgeführt und nicht in dem thread, der AddControl das erste mal aufruft, oder?

0
regex9  04.12.2022, 06:31
@RANGObro

Das ist richtig. Im obigen Beispiel befinden sich die Objekte bei konkreter Ausführung im selben Thread.

1