我正在使用Visual Studio C#制作一款游戏,我希望在编译时自动将窗体最大化适应于任何用户的计算机屏幕。如何实现这个功能?
你可以使用以下方法之一实现:
使用以下代码获取屏幕分辨率,并相应地设置表单的大小。
int height = Screen.PrimaryScreen.Bounds.Height;
int width = Screen.PrimaryScreen.Bounds.Width;
this.WindowState = FormWindowState.Maximized;
来最大化窗体。C#:
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
VB:
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
private void maximiseButton_Click(object sender, EventArgs e)
{
//normalises window
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
this.CenterToScreen();
}
//maximises window
else
{
this.WindowState = FormWindowState.Maximized;
this.CenterToScreen();
}
}
在VS2010中正确的写法:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
private void Frm_Move (object sender, EventArgs e)
{
Top = 0; Left = 0;
Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
}