代码:
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属性,但没有一个强制我的对话框显示在父(调用者)窗口的中心。想法?谢谢。
答案 0 :(得分: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();
}