[英]How can you make the form maximize to any computer screen in a Windows Forms application?
So I am making a game on Visual Studio C# and I want the form to be automatically maximized to any user's computer screen when compiled? 所以我在Visual Studio C#上制作游戏,我希望在编译时将表单自动最大化到任何用户的计算机屏幕? How can I do that?
我怎样才能做到这一点?
You can do it using one of the following -- 您可以使用以下方法之一来完成 -
Get the screen resolution using following code and set the size of your forms accordingly 使用以下代码获取屏幕分辨率,并相应地设置表单的大小
int height = Screen.PrimaryScreen.Bounds.Height; int width = Screen.PrimaryScreen.Bounds.Width;
Set the WindowState property of your form to Maximized
. 将窗体的WindowState属性设置为
Maximized
。
That will cause your form to be maximumized when it's opened. 这将导致您的表单在打开时最大化。
你可以使用this.WindowState = FormWindowState.Maximized;
C#: C#:
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
VB: VB:
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
If you are looking for something that will maximize your window on a first click and normalizes your window on a second click, this will help. 如果您正在寻找能够在第一次点击时最大化窗口并在第二次点击时标准化窗口的内容,这将有所帮助。
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;
On the Form Move Event add this: 在表单移动事件上添加以下内容:
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.