Update einer Control in einem FlowLayoutPanel (gelöst)

  • VB.NET
  • .NET (FX) 4.5–4.8

    Update einer Control in einem FlowLayoutPanel (gelöst)

    Hi,

    ich habe eine meiner Anfragen "toteditiert", weil ich die Lösung zwischenzeitlich selbst gefunden hatte. Das ist nicht ganz die feine Art und deshalb poste ich meine Anfrage nochmal mit Lösung:

    ich habe ein FlowChartPanel.

    Das befülle ich in einer Schleife wie folgt:

    VB.NET-Quellcode

    1. 'Add panel (tile)
    2. Dim myPanel As New Panel
    3. ...
    4. 'Define picture box
    5. Dim myPicturebox As New PictureBox
    6. myPicturebox.Image = copyBitmap 'Load display or error picture
    7. myPanel.Controls.Add(myPicturebox)
    8. ...
    9. 'Construct filename and add label
    10. Dim myLabel As New Label
    11. LabelList.Add(myLabel)
    12. ...
    13. 'Add control to FlowLayoutPanel
    14. FlowLayoutPanel1.Controls.Add(myPanel)


    Ich möchte nun das Bildchen etwa im 5. Panel updaten. Die Frage ist also, wie ich die PictureBox im 5. Panel ansprechen kann.

    Die Antwort ist trivial (man muss halt mit der Syntax klarkommen :) )

    VB.NET-Quellcode

    1. Dim myPicturebox As PictureBox = CType(FlowLayoutPanel1.Controls.Item(k).Controls(i), PictureBox)


    k gibt an welches Panel adressiert wird (Zählung beginnt bei 0 wie üblich).

    i gibt an um welches Control es sich handelt (auch hier beginnt die Zählung bei 0).

    In meinem Fall ist also k=4 (das 5. Panel) und i=0 (das erste Control).

    Ich hoffe, dass die Sache dem einen oder anderen weiter hilft.

    LG
    Peter