2017-12-05 1 views
1

Ich möchte klassisch ein modales Fenster mit dunklem Hintergrund machen.Pop-up modales Dialogfeld mit grauem Hintergrund

Ich weiß nicht, warum das so schwer ist, es zu machen. Ich habe viel versucht, aber es passt einfach nicht zu meinen Bedürfnissen.

Ich habe 10+ modalen Fenster und sie sind Formen angepasst, die sie Gitter hat, Diagramme usw.

Sie sind nicht ‚OK, Nein, Abbrechen‘ Personal.

Ich habe versucht, unten Code anzuwenden. Der Code erstellt grundlegend ein anderes Formular mit schwarzem Hintergrund zwischen dem übergeordneten Formular und dem modalen Formular.

  Form f = new Form(); 
      f.BackColor = Color.Black; 
      f.Size = this.Size; 
      f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
      f.StartPosition = this.StartPosition; 
      f.Opacity = 0.6; 
      f.Show(); 
      notificationSGA nsga = new notificationSGA(Cursor.Position); 
      nsga.ShowDialog(); 
      f.Dispose(); 
      f.Close(); 

Der obige Code funktioniert einwandfrei. Wenn ich jedoch das übergeordnete (Master-) Formular an eine Stelle anstelle der Mitte des Bildschirms verschiebe, erscheint schwarzes Formular immer noch in der Mitte des Bildschirms, nicht als übergeordnetes Element des Bildschirms.

Wie kann ich mein Problem lösen?

Hinweis: Dies ist kein Thema mit unter Frage dupliziert; How to show a pop up message with dark background

Antwort

2

Ändern der .StartPosition-.Manual, so dass Sie .Location, wo Ihre Referenzform festlegen.
Ändern Sie auch den Besitzer in der .Show()-Methode für beide neue Formulare.

Form f = new Form(); 
    //(...) 
    f.Size = this.Size; 
    f.StartPosition = FormStartPosition.Manual; 
    f.Location = this.Location; 
    //(...) 
    f.Show(this); 

    notificationSGA nsga = new notificationSGA(Cursor.Position); 
    nsga.StartPosition = FormStartPosition.CenterParent; 
    nsga.ShowDialog(f); 

    f.Dispose(); 
+0

Sie, Herr. du bist perfekt. –