Überprüfen, welches Object sich im Container befindet?



  • Hi Leute !

    Ich hab füge einem Panel mehrere Sachen hinzu (panel1.Controls.Add(XYZ))

    Wie kann ich nachher prüfen ob es sich bei dem aktuellen Object zB um eine PictureBox handelt?

    for (int i = 0 ; i < panel1.Controls.Count; i++) {
        if (panel1.Controls[i] == PICTUREBOX)
           ...
    
    }
    

    Wisst ihr was ich meine?

    Lg



  • Servus,

    mehrere Möglichkeiten. Hier einfach mal 2 aufgeführt.

    foreach ( Control control in this.panel1.Controls )
    {
        if ( control is PictureBox )
        {
            MessageBox.Show("Katzenklo!!!");
        }
    }
    
    foreach ( Control control in this.panel1.Controls )
    {
        if ( control.GetType().Equals(typeof(PictureBox)) )
        {
            MessageBox.Show("Katzenklo!!!");
        }
    }
    

    mfg
    Hellsgore


Anmelden zum Antworten