全屏Windows窗体超出了屏幕尺寸

时间:2015-09-28 10:47:12

标签: c# .net winforms fullscreen

我有一个WinForms应用程序(.NET 4)需要全屏显示或无边框最大化。

Form_Shown事件中使用以下代码:

#if (DEBUG)
    var debug = true;
#else
    var debug = false;
#endif

this.Text = "";
this.ControlBox = false;
this.ShowInTaskbar = true;
//this.TopMost = debug;
this.TopLevel = true;
this.FormBorderStyle = FormBorderStyle.None;

if (debug) { this.Bounds = Screen.FromControl(this).WorkingArea; }
else { this.WindowState = FormWindowState.Maximized; }

如果仔细观察下面的屏幕截图,顶部和底部区域会被几个像素截断。此外,如果最大化,窗口仍然不会覆盖任务栏。

请注意,我只连接了一台显示器。没有辅助显示器。

对于如何解决上述两个问题的任何建议都将不胜感激。

Screenshot of app in maximized mode

更新:上述代码似乎适用于没有MenuStripStatusStrip的表单。

1 个答案:

答案 0 :(得分:4)

这是我用于全屏的代码。我为表单创建了一个this.ConnectionObject = function(homeState, userId, ws) { this.homeState = homeState; this.userId = userId; this.wsConnection = ws; }, this.createConnectionEntry = function(homeState, userId, ws) { var connObject = new ws.thisRefer.ConnectionObject(homeState, userId, ws); var connectionEntryList = null; if (ws.thisRefer.connectionMap[homeState] != undefined) { connectionEntryList = ws.thisRefer.connectionMap[homeState]; } else { connectionEntryList = new Array(); } connectionEntryList.push(connObject); console.log(connectionEntryList.length); ws.thisRefer.connectionMap[homeState] = connectionEntryList; ws.thisRefer.connecteduserIdMap[userId] = ""; } 属性,当我需要时,我设置了FullScreen

this.FullScreen = true;