在其父级的中心显示对话框
在其父窗体的中心显示对话框是一团糟。这是显示对话框的方法。
我将其父级定位到中心,但无法将对话框居中
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)
{
}
}
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)
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能需要检查
Form.StartPosition
属性。http://msdn.microsoft.com/en -us/library/system.windows.forms.form.startposition.aspx
大致如下:
这当然需要设置表单的父级。
You might want to check the
Form.StartPosition
property.http://msdn.microsoft.com/en-us/library/system.windows.forms.form.startposition.aspx
something along the lines of:
This of course requires setting the form's parent.
请参阅 http://msdn.microsoft。 com/en-us/library/system.windows.forms.form.startposition(v=vs.110).aspx
See http://msdn.microsoft.com/en-us/library/system.windows.forms.form.startposition(v=vs.110).aspx
如果您正在制作自定义 MessageBox,则只需将以下内容放入
您的自定义 MessageBox
formload()
方法中。if you are making a custom MessageBox,you can simply put this:
in your custom MessageBox
formload()
method.另外,如果你想设置任意位置,你可以使用这个
In addition, if you want to set up arbitrary location you can use this