我需要从我的窗口窗体中删除标题栏。但是当我设置
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
标题栏不见了,任务栏也不见了。
所以我需要通过删除标题栏来恢复任务栏。我需要像附图中那样的 from
谁能帮帮我?
最佳答案
一种解决方法是告诉窗口最大边界是多少。您可以通过覆盖 WM_GETMINMAXINFO 窗口消息的默认行为来做到这一点。所以基本上你必须重写表单的 WndProc 方法。
您也可以更改 MaximizedBounds( protected 属性)的值而不是覆盖 WndProc,但如果您这样做,则每次将表单移动到另一个屏幕时都必须设置此属性。
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int x;
public int y;
public POINT()
{
}
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
}
[StructLayout(LayoutKind.Sequential)]
public class MINMAXINFO
{
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
const int WM_GETMINMAXINFO = 0x0024;
if (m.Msg == WM_GETMINMAXINFO)
{
MINMAXINFO minmaxinfo = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
var screen = Screen.FromControl(this);
minmaxinfo.ptMaxPosition = new POINT(screen.WorkingArea.X, screen.WorkingArea.Y);
minmaxinfo.ptMaxSize = new POINT(screen.WorkingArea.Width, screen.WorkingArea.Height);
Marshal.StructureToPtr(minmaxinfo, m.LParam, false);
}
}
关于c# - 删除标题栏但需要 C# Windows 窗体中的任务栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25742164/