【问题标题】:Remove title bar but need task bar in C# Windows form删除标题栏但需要 C# Windows 窗体中的任务栏
【发布时间】:2014-09-09 10:19:05
【问题描述】:

我需要从我的 Windows 窗体中删除标题栏。但是当我设置

FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

标题栏不见了,同时也看不到任务栏。

所以我需要通过删除标题栏来恢复任务栏。我需要像所附图片中的那样

谁能帮帮我?

【问题讨论】:

  • 表单中没有ShowInTaskbar 属性吗?是否设置为 true?

标签: c# winforms


【解决方案1】:

一种方法是告诉窗口最大界限是多少。您可以通过覆盖 WM_GETMINMAXINFO 窗口消息的默认行为来做到这一点。所以基本上你必须重写表单的 WndProc 方法。

您也可以更改 MaximizedBounds(受保护的属性)的值,而不是覆盖 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);
        }
    }

【讨论】:

  • 我会把POINT 变成struct
【解决方案2】:

您应该检查ShowInTaskbar 属性是否已在设计时或运行时关闭。即使边框是None,它也会默认显示在任务栏。

【讨论】:

    猜你喜欢
    • 2011-11-20
    • 2016-12-23
    • 2011-08-14
    • 2011-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多