C# 全屏windows窗体,但带有标题栏
我在关注这篇文章, 这使我的windows窗体全屏显示,但它也隐藏了标题栏 我想隐藏任务栏,但希望有我的标题栏 “targetForm.FormBorderStyle=FormBorderStyle.None;”隐藏我的标题栏,但删除此标题栏会显示任务栏,因此是否仍有隐藏任务栏并在windows应用程序中保留标题栏的方法?谢谢C# 全屏windows窗体,但带有标题栏,c#,.net,C#,.net,我在关注这篇文章, 这使我的windows窗体全屏显示,但它也隐藏了标题栏 我想隐藏任务栏,但希望有我的标题栏 “targetForm.FormBorderStyle=FormBorderStyle.None;”隐藏我的标题栏,但删除此标题栏会显示任务栏,因此是否仍有隐藏任务栏并在windows应用程序中保留标题栏的方法?谢谢 using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.
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;
}
}
}
使用系统;
使用系统图;
使用System.Windows.Forms;
使用System.Runtime.InteropServices;
名称空间MyClass
{
公共类WinApi
{
[DllImport(“user32.dll”,EntryPoint=“GetSystemMetrics”)]
公共静态外部int GetSystemMetrics(int which);
[DllImport(“user32.dll”)]
公共静态外部无效
设置窗口位置(IntPtr hwnd、IntPtr hwndInsertAfter、,
整数X、整数Y、整数宽度、整数高度、整数标志);
私有常量int SM_CXSCREEN=0;
私有常量int SM_CYSCREEN=1;
私有静态IntPtr HWND_TOP=IntPtr.Zero;
private const int SWP_SHOWWINDOW=64;//0x0040
公共静态int ScreenX
{
获取{return GetSystemMetrics(SM_CXSCREEN);}
}
公共静态整型屏幕
{
获取{return GetSystemMetrics(SM_CYSCREEN);}
}
公共静态无效设置WinFullScreen(IntPtr hwnd)
{
设置窗口位置(hwnd、hwnd_顶部、0、0、ScreenX、ScreenY、SWP_显示窗口);
}
}
///
///类,用于保留/恢复窗体的状态
///
公共类FormState
{
私有FormWindowsState winState=FormWindowsState.Normal;
private FormBorderStyle brdStyle=FormBorderStyle.sizeable;
最上层的私人住宅;
私有矩形边界;
私有布尔值最大化=假;
公共表格(表格targetForm)
{
如果(!IsMaximized)
{
IsMaximized=真;
Save(targetForm);
targetForm.WindowsState=FormWindowsState.Maximized;
targetForm.FormBorderStyle=FormBorderStyle.None;
//targetForm.TopMost=真;
设置WinFullScreen(targetForm.Handle);
}
}
公共作废保存(表格targetForm)
{
winState=targetForm.WindowsState;
brdStyle=targetForm.FormBorderStyle;
topMost=targetForm.topMost;
bounds=targetForm.bounds;
}
公共无效恢复(表单targetForm)
{
targetForm.WindowsState=winState;
targetForm.FormBorderStyle=brdStyle;
targetForm.TopMost=最上面;
targetForm.Bounds=边界;
IsMaximized=false;
}
}
}
您可以将其设置为FormBorderStyle.FixedToolWindow代码>,而不仅仅是任务栏被隐藏。您的意思是“全屏窗口窗体,但带有任务栏”对吗?(在你的问题标题)没有任务栏,但有工具栏这显示了标题栏,但令人惊讶的是,最大化和最小化按钮看不到标题栏,而关闭是存在的。如何使这些按钮返回targetForm.MinimizeBox=true;和targetForm.MaximizeBox=true;不行是的,那是因为你有固定的窗户。如果您允许用户更改大小。你会把扣子拿回来的。不幸的是,您想要的行为没有FormBorderStyle。你可能需要自己写一个。这是一个非常独特的要求吗?我想很多开发者都需要这个。有没有指向一些文章/博客的指针?无论如何,谢谢。我说这是一个独特的要求,因为我找不到任何办法来解决你的问题。Sry。