Autor Beitrag
masteroffinalfantasy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: So 13.07.08 12:12 
Moin Moin,

in Delphi gibt es ja die praktische FindComponent Methode... gibts sowas praktisches auch für C#?

Hab leider nichts auf Anhieb gefunden.

mfg


Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am So 13.07.2008 um 12:18
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 13.07.08 12:19 
In C# nicht, das ist nur die Sprache ;-)

Im Framework hat eine Form die Eigenschaft Controls, welche man so ansprechen kann:
ausblenden C#-Quelltext
1:
Button meinButton = (Button) this.Controls["button1"];					


Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: So 13.07.08 13:36 
Hallo,

Christians Antwort ist zwar korrekt, aber für die Praxis nicht ausreichend, da unter NET mit der Eigenschaft Controls immer nur eine Ebene erfasst wird. Entweder Du musst bei der Suche alle Controls rekursiv durchsuchen; oder Du benutzt die passende Methode in der richtigen Fassung (beachte den zweiten Parameter):
ausblenden C#-Quelltext
1:
Control[] found = this.Controls.Find("button1"true);					

Gruß Jürgen
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: So 13.07.08 13:55 
Danke euch beiden für die schnelle Hilfe :)

Problem gelöst :)
goldensurfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45



BeitragVerfasst: Do 17.07.08 14:39 
Habe gerade ein ähnliches Problem: ich will in einer Schleife durch alle Controls eines Formulars gehen und, falls das Formular ein Panel ist, weitere Aktionen damit anstellen:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
      Control ctl = null;
      for (int i = 0; i < this.Controls.Count; i++)
      {
        ctl = this.Controls[i];
        if (ctl is Panel)
        {
          MessageBox.Show(ctl.Tag.ToString());
        }
      }


Problem ist hier wie ganz oben beschrieben - ich bekomme nur die Controls, die direkt auf dem Formular liegen. Die Find-Methode kann ich nicht nehmen, da ich den Namen nicht kenne.
Weiß jemand eine Lösung, wie ich ohne Rekursion an alle Controls eines Formulars komme?

Danke!

Moderiert von user profile iconChristian S.: Code- durch C#-Tags ersetzt
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Do 17.07.08 14:58 
user profile icongoldensurfer hat folgendes geschrieben:
falls das Formular ein Panel ist
Das könnte schwierig werden :mrgreen: .

Was spricht denn gegen Rekursion?
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Do 17.07.08 16:16 
user profile iconKhabarakh hat folgendes geschrieben:
Was spricht denn gegen Rekursion?

Die Tatsache, dass ihm diese Hinweise nicht genügen. Jürgen
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Do 17.07.08 17:40 
Och, Cross-Posts sind doch ein gutes Beispiel :zwinker: .