Autor Beitrag
Felix2000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Do 18.08.11 13:30 
Hi Folks !

Ich möchte ein Formular öffnen, dass ich erstellt habe und diese soll sich öffnen, wenn ich in meiner Anwendung auf einen Button drücke.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
private void button2_Click(object sender, EventArgs e)
{

     form2.ActiveForm.Show();

}


Dieser Kode bewirkt leider gar nichts. Kann mir jemand von euch weiterhelfen bei dem Problem?

Greetz
Felix
mats74
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189
Erhaltene Danke: 26

Win 10
VS 2017/19, C++, C#
BeitragVerfasst: Do 18.08.11 13:41 
Hallo Felix2000

Instanziere die zweite Form und rufe das Form mit der Methode Show() oder ShoWDialog() auf

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();

            form2.Show();
            // oder
            //form2.ShowDialog();
        }


Gruss
mats74
Felix2000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Do 18.08.11 14:13 
Hi Folks !

ok super das hat geklappt. Besteht eigentlich die Möglichkeit, die Startposition des Formulars exakt festzulegen? Kann man evtl. einen Focus auf das Form setzen, so dass es zwingend beachtet werden muss?

ausblenden Quelltext
1:
2:
form2.StartPosition    //hier weiß ich nicht, was ich dort eintragen müsste?
form2.Focus();         //ist das richtig?


Greetz
Felix
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Do 18.08.11 14:24 
Du kannst bevor du das Formular anzeigen lässt mittels StartPosition einstellen wie es sich verhält, dabei hast du 5 Auswahlmöglichkeiten. Wenn du es auf Manual stellst kannst du mittels form.Location die genaue Position einstellen.
Felix2000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Do 18.08.11 14:37 
das versteht ich jetzt ehrlich gesgat nicht, Könntest Du mir evtl. dafür mal ein Codebeispiel posten?

Greetz
felix
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Do 18.08.11 14:49 
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Form myForm = new Form();

//Manuell am linken oberen Rand
//myForm.StartPosition = FormStartPosition.Manual;
//myForm.Location = new Point(0,0);

//In der Mitte des Bildschirms
myForm.StartPosition = FormStartPosition.CenterScreen;

myForm.Show();
Felix2000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Do 18.08.11 15:04 
Hi Folks !

Sehr schön, das hat schon mal geklappt. Wie kannich denn das jetzt noch mit dem Fokus sicherstellen, so dass das Fenster explizit vom User beachtet werden muss?

form.Focus(); bewirkt leider nichts !

Greetz
Felix
mats74
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189
Erhaltene Danke: 26

Win 10
VS 2017/19, C++, C#
BeitragVerfasst: Do 18.08.11 15:22 
... Methode ShowDialog() anstelle Show() sollte eigentlich genügen (wie oben schon erwähnt).
Dann wird das Form als Dialog und für den User zwingend angezeigt.

Gruss
mats74