0

I want to make classic a modal Window with dark background.

I don't know why this is so hard to make it. I tried a lot way to do it, however it just doesn't fit with my needs.

I have 10+ modal Windows and they are customized Forms which contain grids, charts, etc.

They are not 'OK, No, Cancel' stuff.

My code basically creates another Form with black background between parent Form and modal Form:

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();

Above code works perfectly fine. However if I move the parent (master) Form to somewhere instead of center of the screen, the black Form still appears at the center of the screen, not centered to the parent Form.

How can I solve my issue?

Note: This is not duplicated topic with below question:
How to show a pop up message with dark background

Jimi
  • 29,621
  • 8
  • 43
  • 61
john true
  • 263
  • 1
  • 5
  • 26

1 Answers1

4

Change the .StartPosition to .Manual so that you can set .Location to where your reference form is.
Also, change the owner in the .Show() method for both new Forms.

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

f.Show(this);

using (var nsga = new notificationSGA(Cursor.Position)) {
    nsga.StartPosition = FormStartPosition.CenterParent;
    nsga.ShowDialog(f);
}
f.Dispose();
Jimi
  • 29,621
  • 8
  • 43
  • 61