【发布时间】:2011-02-26 15:46:59
【问题描述】:
所以我正在 Visual Studio C# 上制作游戏,我希望表单能够 编译时自动最大化到任何用户的计算机屏幕? 我怎样才能做到这一点?
【问题讨论】:
-
我确定您的意思是运行时,而不是编译时。
-
答案取决于您编码的平台。 WPF?银光?表格?等
所以我正在 Visual Studio C# 上制作游戏,我希望表单能够 编译时自动最大化到任何用户的计算机屏幕? 我怎样才能做到这一点?
【问题讨论】:
您可以使用以下方法之一来做到这一点--
使用以下代码获取屏幕分辨率并相应地设置表单的大小
int height = Screen.PrimaryScreen.Bounds.Height;
int width = Screen.PrimaryScreen.Bounds.Width;
【讨论】:
将表单的WindowState 属性设置为Maximized。
这将导致您的表单在打开时最大化。
【讨论】:
FormBorderStyle.None 来去除边框,以获得更真正的最大化感觉,不添加边框。
您可以使用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);
}
【讨论】: