【发布时间】:2023-03-11 22:05:01
【问题描述】:
在其父窗体的中心显示一个对话框是一团糟。这是一种显示对话框的方法。
我将其父级定位到中心,但无法将 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)
{
}
}
【问题讨论】:
-
我也会小心多线程。控件的属性(至少是那些处理用户界面的)只能从创建它们的线程中更改。我在这里看不到更大的图景,所以我不知道您为什么要在其自己的线程中创建每个表单,但请记住这一点。
标签: c# winforms .net-4.0 positioning center