灰色背景弹出模态对话框
Pop-up modal dialog with grey background
我想将 classic 设为深色背景的模态Window。
我不知道为什么做起来这么难。我尝试了很多方法,但是它不符合我的需求。
我有 10 多个模态Windows,它们是包含网格、图表等的自定义表单
它们不是 'OK, No, Cancel' 东西。
我的代码基本上在父表单和模态表单之间创建了另一个具有黑色背景的表单:
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();
以上代码运行良好。但是,如果我将父(主)窗体移动到某个地方而不是屏幕中心,黑色窗体仍然出现在屏幕中心,而不是父窗体的中心。
我该如何解决我的问题?
注意:这不是与以下问题重复的主题:
将 .StartPosition
更改为 .Manual
以便您可以将 .Location
设置为参考表格所在的位置。
此外,在 .Show()
方法中更改两个新表单的所有者。
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();
我想将 classic 设为深色背景的模态Window。
我不知道为什么做起来这么难。我尝试了很多方法,但是它不符合我的需求。
我有 10 多个模态Windows,它们是包含网格、图表等的自定义表单
它们不是 'OK, No, Cancel' 东西。
我的代码基本上在父表单和模态表单之间创建了另一个具有黑色背景的表单:
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();
以上代码运行良好。但是,如果我将父(主)窗体移动到某个地方而不是屏幕中心,黑色窗体仍然出现在屏幕中心,而不是父窗体的中心。
我该如何解决我的问题?
注意:这不是与以下问题重复的主题:
将 .StartPosition
更改为 .Manual
以便您可以将 .Location
设置为参考表格所在的位置。
此外,在 .Show()
方法中更改两个新表单的所有者。
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();