我正在用C#编写一个Web浏览器,因此我为它制作了一个启动画面。然而,在启动时,启动画面并不位于屏幕中心。那么,有什么方法可以在启动时将窗体居中显示吗?
代码如下:
public splash()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
我正在用C#编写一个Web浏览器,因此我为它制作了一个启动画面。然而,在启动时,启动画面并不位于屏幕中心。那么,有什么方法可以在启动时将窗体居中显示吗?
代码如下:
public splash()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
StartPosition = FormStartPosition.CenterScreen;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//Method 1. center at initilization
this.StartPosition = FormStartPosition.CenterScreen;
//Method 2. The manual way
this.StartPosition = FormStartPosition.Manual;
this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height)/2;
this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width)/2;
}
}
}
如果您想通过GUI执行此操作并且使用Visual Studio,则请按照以下步骤进行操作:
1. 在表单设计器中打开您的表单
2. 导航到表单属性
3. 将“StartPosition”更改为“CenterScreen”