C# 如何使窗体最大化到Windows窗体应用程序中的任何计算机屏幕?
因此,我正在Visual Studio C#上制作一个游戏,我希望表单 编译时自动最大化到任何用户的计算机屏幕? 我该怎么做 将表单属性设置为C# 如何使窗体最大化到Windows窗体应用程序中的任何计算机屏幕?,c#,screen,maximize,C#,Screen,Maximize,因此,我正在Visual Studio C#上制作一个游戏,我希望表单 编译时自动最大化到任何用户的计算机屏幕? 我该怎么做 将表单属性设置为最大化 这将导致表单在打开时最大化。您可以使用以下方法之一进行此操作:-- 设置窗体WindowsState=FormWindowsState.Maximized 使用以下代码获得屏幕分辨率,并相应地设置窗体的大小 int height = Screen.PrimaryScreen.Bounds.Height; int width = Screen.Pr
最大化
这将导致表单在打开时最大化。您可以使用以下方法之一进行此操作:--
int height = Screen.PrimaryScreen.Bounds.Height;
int width = Screen.PrimaryScreen.Bounds.Width;
您可以使用
this.WindowState=FormWindowState.Maximized代码>在VS2010中正确:
this.FormBorderStyle=System.Windows.Forms.FormBorderStyle.None代码>
转到“以视图代码形式加载表单”并使用此代码:
C#:
VB:
如果您正在寻找一种可以在第一次单击时使窗口最大化并在第二次单击时使窗口正常化的方法,这将有所帮助
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();
}
}
在表单移动事件中添加以下内容:
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);
}
我相信你的意思是运行时,而不是编译时。答案取决于你为哪个平台编写代码。WPF?银灯?WinForms?等等。此外,可以将设置为FormBorderStyle.None
也可以删除边框,为获得更真实的最大化效果,不添加边框。WindowsState=FormWindowsState.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();
}
}
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);
}