【发布时间】:2018-05-22 03:25:18
【问题描述】:
快速提问,希望可以轻松解决。
我对 C# 有点陌生,并试图在第二个表单打开时将其居中显示在辅助屏幕上。到目前为止,我可以让它在第二个屏幕上打开没问题,但它位于左上角,我无法让它居中。我知道Location = Screen.AllScreens[1].WorkingArea.Location; 将把它放在所述工作区的左上角。我想知道是否有办法(基本上)将.Location 更改为其他无论实际屏幕尺寸如何都可以居中的东西?这将适用于具有不同屏幕尺寸的多个不同系统。
这是我到目前为止的代码。
在第一个表单上。
public partial class FrmPrompt : Form
{
public FrmPrompt()
{
InitializeComponent();
}
private void ButNo_Click(object sender, EventArgs e)
{
frmConfirm confirm = new frmConfirm();
Screen[] screens = Screen.AllScreens;
lblConfirmMsg.Text = "Please Wait For Customer To Confirm...";
butContinue.Hide();
confirm.Show();
}
}
关于第二种形式:
public partial class frmConfirm : Form
{
public frmConfirm()
{
InitializeComponent();
Location = Screen.AllScreens[1].WorkingArea.Location;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
谢谢!
【问题讨论】:
-
Form.CenterToScreen() 没有做你想做的事吗?
-
如果你阅读那里写的内容,你会看到不要直接从你的代码中调用它备注
标签: c# forms location center screens