【问题标题】:Pop-up modal dialog with grey background [duplicate]带有灰色背景的弹出模式对话框[重复]
【发布时间】:2018-05-19 11:05:09
【问题描述】:

我想让经典的模态窗口带有深色背景。

我不知道为什么这很难做到。我尝试了很多方法来做到这一点,但它不符合我的需求。

我有 10 多个模态窗口,它们是包含网格、图表等的自定义表单。

它们不是“好的,不,取消”的东西。

我的代码基本上在父表单和模态表单之间创建了另一个黑色背景的表单:

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

上面的代码工作得很好。但是,如果我将父(主)窗体移动到某处而不是屏幕中心,黑色窗体仍会出现在屏幕中心,而不是以父窗体为中心。

如何解决我的问题?

注意:这不是与以下问题重复的主题:
How to show a pop up message with dark background

【问题讨论】:

    标签: c# winforms modal-dialog screen


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多