全屏窗口形式,但有标题栏

本文关键字:标题栏 窗口 | 更新日期: 2023-09-27 18:13:51

我在看这篇文章,http://www.vesic.org/english/blog-eng/net/full-screen-maximize/

这使我的窗口窗体全屏,但它也隐藏标题栏。

我想隐藏任务栏,但我想有我的标题栏。

" targetForm。隐藏我的标题栏,但删除这个显示任务栏,所以有隐藏任务栏和保留标题栏在windows应用程序?由于

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace myClasses
{
    public class WinApi
    {
        [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
        public static extern int GetSystemMetrics(int which);
        [DllImport("user32.dll")]
        public static extern void
            SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
                         int X, int Y, int width, int height, uint flags);
        private const int SM_CXSCREEN = 0;
        private const int SM_CYSCREEN = 1;
        private static IntPtr HWND_TOP = IntPtr.Zero;
        private const int SWP_SHOWWINDOW = 64; // 0x0040
        public static int ScreenX
        {
            get { return GetSystemMetrics(SM_CXSCREEN); }
        }
        public static int ScreenY
        {
            get { return GetSystemMetrics(SM_CYSCREEN); }
        }
        public static void SetWinFullScreen(IntPtr hwnd)
        {
            SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
        }
    }
    /// <summary>
    /// Class used to preserve / restore state of the form
    /// </summary>
    public class FormState
    {
        private FormWindowState winState = FormWindowState.Normal;
        private FormBorderStyle brdStyle = FormBorderStyle.Sizable;
        private bool topMost;
        private Rectangle bounds;
        private bool IsMaximized = false;
        public void Maximize(Form targetForm)
        {
            if (!IsMaximized)
            {
                IsMaximized = true;
                Save(targetForm);
                targetForm.WindowState = FormWindowState.Maximized;
                targetForm.FormBorderStyle = FormBorderStyle.None;
                //targetForm.TopMost = true;
                WinApi.SetWinFullScreen(targetForm.Handle);
            }
        }
        public void Save(Form targetForm)
        {
            winState = targetForm.WindowState;
            brdStyle = targetForm.FormBorderStyle;
            topMost = targetForm.TopMost;
            bounds = targetForm.Bounds;
        }
        public void Restore(Form targetForm)
        {
            targetForm.WindowState = winState;
            targetForm.FormBorderStyle = brdStyle;
            targetForm.TopMost = topMost;
            targetForm.Bounds = bounds;
            IsMaximized = false;
        }
    }
}

全屏窗口形式,但有标题栏

可以设置为FormBorderStyle.FixedToolWindow;,只隐藏任务栏