Autor Beitrag
Talemantros
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Do 14.05.15 12:59 
Hallo,
ich würde gern eine Methode haben, die variable eine Form aufrufen kann.
Leider bekomme ich den Parameter mit der Form nicht übergeben

Habe es mal so versucht

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
        private void ShowForm(Form form)
        {
            var mydlg = new form();
            mydlg.show(this);
        }


Könnt ihr mir da helfen?

Gruß
Palladin007
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1282
Erhaltene Danke: 182

Windows 11 x64 Pro
C# (Visual Studio Preview)
BeitragVerfasst: Do 14.05.15 13:07 
Du musst den Typ übergeben. Hier bietet sich dazu eine generische Methode an, mit der Einschränkung, dass der generische Typ einen parameterlosen Konstruktor haben soll.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
private void ShowForm<TForm>()
    where TForm: Form, new()
{
    var form = new TForm();
    form.Show(this);
}


Oder Du verwendest Die Activator-Klasse, die kann ein Objekt mit einem Type-Objekt erzeugen.
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 16.05.15 13:36 
Schaue ich mir an..
Vielen Dank