在其父级的中心显示对话框 [英] Show Dialog box at center of its parent

查看:95
本文介绍了在其父级的中心显示对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其父窗体的中心显示一个DialogBox真是一团糟.这是一种显示对话框的方法.

It's been a mess to show a DialogBox at the center of its parent form. Here is a method to show a dialog.

我将其父对象置于居中位置,但无法居中对话框

I am positioning its parent to center but not able to center the DialogBox

private void OpenForm(Object point, Object height, Object width)
{
    FormLoading frm = new FormLoading();
    Point temp = (Point)point;
    Point location = new Point(temp.X + (int)((int)width) / 2, 
                               temp.Y + (int)((int)height) / 2);
    frm.Location = location;
    frm.ShowDialog();
}

private void btnView_Click(object sender, EventArgs e)
{
    try
    {                    
        ThreadStart starter= delegate { OpenForm(currentScreenLocation, 
                                                 this.Height, this.Width); };
        Thread t = new Thread(starter);
        t.Start();
        ////// Some functionality here...
        t.Abort();
    }
    catch (Exception)
    {
    }
}

推荐答案

您可能要检查Form.StartPosition属性.

http://msdn.microsoft. com/en-us/library/system.windows.forms.form.startposition.aspx

类似的东西:

private void OpenForm(Form parent)
{
    FormLoading frm = new FormLoading();
    frm.Parent = parent;
    frm.StartPosition = FormStartPosition.CenterParent;
    frm.ShowDialog();
}

这当然需要设置表单的父项.

This of course requires setting the form's parent.

这篇关于在其父级的中心显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆