2

编码:

    void btnSettings_Click(object obj, EventArgs args)
    {
        frmSettings dialogSettings = new frmSettings();
        dialogSettings.Modal = true;
        dialogSettings.TransientFor = this;
        dialogSettings.Parent = this;
        dialogSettings.ParentWindow = this.GdkWindow;
        dialogSettings.SetPosition(Gtk.WindowPosition.CenterOnParent);

        dialogSettings.Show();
    }

我尝试了 TransientFor、Parent、ParentWindow 属性,但它们都没有强制我的对话框显示在父(调用者)窗口的中心。想法?谢谢你。

4

1 回答 1

0

更好的选择是在构造函数中设置 Dialog 的父级:

public MyDialog (Gtk.Window parent) 
         : base ("My title", parent, Gtk.DialogFlags.Modal, new object[0])
{
    this.Build();
}

public override void Dispose ()
{
    Destroy();
    base.Dispose();
}

然后像这样从父窗口调用它:

var dialog = new MyDialog(this);
try 
{
    var response = (ResponseType) dialog.Run();
    //handle response...
}
finally
{
    dialog.Dispose();
}
于 2014-12-25T12:04:44.393 回答