Arc*_*nox 30
我这样做是通过这个代码:
this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
this.WindowState = FormWindowState.Maximized;
Run Code Online (Sandbox Code Playgroud)
Per*_*Per 21
这可能就是你想要的.它创建了一个"最大化"窗口而不隐藏任务栏.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e )
{
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
Left = Top = 0;
Width = Screen.PrimaryScreen.WorkingArea.Width;
Height = Screen.PrimaryScreen.WorkingArea.Height;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我在这里回答过:
我在描述中遗漏了一件事——我关闭了最大化按钮。当我测试重新打开该属性时,任务栏再次出现。显然,它假设如果您不需要最大化按钮,那么您正在创建一个信息亭样式的应用程序,在该应用程序中您不希望用户看到除应用程序屏幕之外的任何内容。不完全符合我的预期,但我猜是有效的。
我遇到了这个问题,并在杰夫的帮助下解决了。首先,将窗口状态设置为最大化。但不要禁用 MaximizeBox。然后,如果您希望禁用 MaximizeBox,您应该以编程方式执行此操作:
private void frmMain_Load(object sender, EventArgs e)
{
this.MaximizeBox = false;
}
Run Code Online (Sandbox Code Playgroud)
小智 6
Arcanox 的答案对于单个显示器来说非常好,但是如果您在最左边以外的任何屏幕上尝试它,它只会使表单消失。我改用下面的代码。
var workingArea = Screen.FromHandle(Handle).WorkingArea;
MaximizedBounds = new Rectangle(0, 0, workingArea.Width, workingArea.Height);
WindowState = FormWindowState.Maximized;
Run Code Online (Sandbox Code Playgroud)
唯一的区别是我将顶部和左侧的值覆盖为 0, 0,因为它们在其他屏幕上会有所不同。