我正在使用C#編寫Web瀏覽器,因此我爲它啓動了一個啓動畫面。但是,啓動畫面不在啓動時位於屏幕中央。那麼有沒有辦法在啓動時將表格居中?啓動時的中心窗體
工作代碼:
public splash()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
我正在使用C#編寫Web瀏覽器,因此我爲它啓動了一個啓動畫面。但是,啓動畫面不在啓動時位於屏幕中央。那麼有沒有辦法在啓動時將表格居中?啓動時的中心窗體
工作代碼:
public splash()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
StartPosition = FormStartPosition.CenterScreen;
form.StartPosition = FormStartPosition.CenterScreen;
見MSDN。
如果你想從GUI做到這一點,你與Visual Studio的工作,然後使用以下步驟:
1.打開窗體在窗體設計
2.導航形成性能
3.更改「StartPosition」到「CenterScreen」
我不敢相信我真的錯過了!它一直在屬性面板中。 – pcnThird
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自定義的最佳位置。考慮使用Form1.Designer.cs代替。 –
splash.Designer.cs最有可能在你的情況下 –