Come trovare un controllo in base al nome del controllo

0

Domanda

Voglio trovare un controllo in base al nome. Questo è ciò che ho finora:

private Point FindControlLocation(string ControlName, Control ParentControl)
{
    //Code...
}

Grazie per qualsiasi aiuto!

c# controls winforms
2021-11-12 23:53:57
1

Migliore risposta

1

Non avete davvero bisogno di controllo parentale, basta usare la Forma e l'opzione ricorsiva da Controls.Find():

private Point FindControlLocation(string ControlName)
{
    Control ctl = this.Controls.Find(ControlName, true).FirstOrDefault() as Control;
    return (ctl != null) ? ctl.Location : new Point();
}
2021-11-13 01:54:51

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................