myq*_*day 61 .net c# taskbar fullscreen winforms
我有一个需要全屏运行的.net Windows应用程序.当应用程序启动时,任务栏显示在主窗体的顶部,只有在通过单击或使用ALT-TAB激活窗体时它才会消失.表单的当前属性如下:
我尝试在表单加载中添加以下内容,但没有一个对我有用:
有没有办法在.NET中执行它,或者我必须调用本机Windows方法,如果是这样,我们非常感谢代码片段.
非常感谢
TcK*_*cKs 95
使用:
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
Run Code Online (Sandbox Code Playgroud)
然后将表单放在任务栏上.
mam*_*ius 50
我已经尝试了很多解决方案,其中一些解决方案适用于Windows XP,而且所有解决方案都无法在Windows 7上运行.毕竟我写了一个简单的方法来实现.
private void GoFullscreen(bool fullscreen)
{
if (fullscreen)
{
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
}
else
{
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
}
}
Run Code Online (Sandbox Code Playgroud)
代码的顺序很重要,如果你改变WindwosState和FormBorderStyle的位置将无法工作.
这种方法的一个优点是使TOPMOST处于假状态,允许其他形式通过主窗体.
它绝对解决了我的问题.
小智 14
这就是我如何使表格全屏.
private void button1_Click(object sender, EventArgs e)
{
int minx, miny, maxx, maxy;
inx = miny = int.MaxValue;
maxx = maxy = int.MinValue;
foreach (Screen screen in Screen.AllScreens)
{
var bounds = screen.Bounds;
minx = Math.Min(minx, bounds.X);
miny = Math.Min(miny, bounds.Y);
maxx = Math.Max(maxx, bounds.Right);
maxy = Math.Max(maxy, bounds.Bottom);
}
Form3 fs = new Form3();
fs.Activate();
Rectangle tempRect = new Rectangle(1, 0, maxx, maxy);
this.DesktopBounds = tempRect;
}
Run Code Online (Sandbox Code Playgroud)
我一直在SO和其他一些站点中寻找此问题的答案,但是有人给我一个答案很复杂,而另一些问题根本无法正常工作,因此经过大量代码测试后,我解决了这个难题。
注意:我使用的是Windows 8,并且任务栏未处于自动隐藏模式。
我发现在执行任何修改之前将WindowState设置为“普通”将通过未覆盖的任务栏停止错误。
我创建了具有两个方法的此类,第一个方法进入“全屏模式”,第二个离开“全屏模式”。因此,您只需要创建此类的对象,然后将要设置全屏的Form作为参数传递给EnterFullScreenMode方法或LeaveFullScreenMode方法:
class FullScreen
{
public void EnterFullScreenMode(Form targetForm)
{
targetForm.WindowState = FormWindowState.Normal;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.WindowState = FormWindowState.Maximized;
}
public void LeaveFullScreenMode(Form targetForm)
{
targetForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
targetForm.WindowState = FormWindowState.Normal;
}
}
Run Code Online (Sandbox Code Playgroud)
private void fullScreenToolStripMenuItem_Click(object sender, EventArgs e)
{
FullScreen fullScreen = new FullScreen();
if (fullScreenMode == FullScreenMode.No) // FullScreenMode is an enum
{
fullScreen.EnterFullScreenMode(this);
fullScreenMode = FullScreenMode.Yes;
}
else
{
fullScreen.LeaveFullScreenMode(this);
fullScreenMode = FullScreenMode.No;
}
}
Run Code Online (Sandbox Code Playgroud)
我将相同的答案放在另一个不确定的问题上,我不确定是否重复。(链接到另一个问题:如何使WinForms应用全屏显示)
小智 5
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
Run Code Online (Sandbox Code Playgroud)