我正在使用C#为应用程序提供“全屏模式”,使用无边框表单和最大化方法。当我将窗体设置为无边框,而不是最大化时,这非常有效--您在屏幕上所能看到的就是窗体,任务栏被覆盖。但是,如果我手动最大化窗体(用户交互),然后尝试使其无边框和最大化,任务栏将绘制在窗体上(因为我没有使用WorkingArea,窗体上的部分控件将被隐藏。其预期行为是不显示任务栏)。我尝试将窗体的属性TopMost设置为true,但似乎没有任何效果。
有没有办法重写它,使其始终覆盖任务栏?
if (this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.None)
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
}
else
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
}
if (this.WindowState != FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Maximized;
}
else
{
if (this.FormBorderStyle == System.Windows.Forms.FormBorderStyle.Sizable) this.WindowState=FormWindowState.Normal;
}发布于 2013-02-11 01:07:05
但是,如果我手动最大化表单(用户交互)...
问题是您的窗口已经在内部标记为最大化状态。所以再次最大化它不会改变表单的当前大小。这将使任务栏暴露。您需要先将其恢复到正常状态,然后再恢复到最大化状态。是的,它有一点闪烁。
private void ToggleStateButton_Click(object sender, EventArgs e) {
if (this.FormBorderStyle == FormBorderStyle.None) {
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Normal;
}
else {
this.FormBorderStyle = FormBorderStyle.None;
if (this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal;
this.WindowState = FormWindowState.Maximized;
}
}发布于 2013-02-10 09:02:35
不知道为什么会发生这种情况,我讨厌那些假设他们可以占据我所有屏幕的应用程序。虽然这对于1024x768的显示器来说可能是可以接受的,但当这该死的东西决定拥有我的屏幕时,我的30英寸显示器就被浪费了。
所以我要说的是,也许应该把重点放在确保你所有的控件在上都是可见的,而不是最大化窗口。
您可以随时检测窗口大小的更改,然后覆盖默认行为,从而处理遇到的意外问题。但是,计算窗口需要多大并相应地设置大小,而不是最大化并占据整个30英寸的显示。
我的2美分,这正是我的想法的价值所在。)
发布于 2013-02-10 22:01:28
您可以尝试使用WinApi SetWindowPos方法,如下所示:
public static class WinApi
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int x, int y, int width, int height,
uint flags);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
const uint SWP_NOSIZE = 0x0001;
const uint SWP_NOMOVE = 0x0002;
const uint SWP_SHOWWINDOW = 0x0040;
public static void SetFormTopMost(Form form)
{
SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
}在您的表单中,这样调用它:
WinApi.SetFormTopMost(this);https://stackoverflow.com/questions/14793428
复制相似问题