全屏模式,但不要覆盖任务栏
我有一个WinForms应用程序,登录时设置为全屏模式。
我的问题是它还覆盖了Windows任务栏。 我不希望我的应用程序覆盖任务栏。
如何才能做到这一点?
这可能是你想要的。 它创建了一个“最大化”窗口而不隐藏任务栏。
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load( object sender, EventArgs e ) { FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; Left = Top = 0; Width = Screen.PrimaryScreen.WorkingArea.Width; Height = Screen.PrimaryScreen.WorkingArea.Height; } }
我这样做是通过这个代码:
this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea; this.WindowState = FormWindowState.Maximized;
我在这里回答:
我遗漏了一个描述 – 我关闭了最大化按钮。 当我测试重新打开该属性时,任务栏再次出现。 显然,它假设您不想要最大化按钮,而是创建一个自助服务终端风格的应用程序,您不希望用户看到除应用程序屏幕之外的任何内容。 不完全是我所期望的,但我认为是有效的。
我遇到了这个问题,并在杰夫的帮助下解决了这个问题。 首先,将windowstate设置为Maximized。 但不要禁用MaximizeBox。 然后,如果要禁用MaximizeBox,则应以编程方式执行此操作:
private void frmMain_Load(object sender, EventArgs e) { this.MaximizeBox = false; }
如果您有多个屏幕,则必须重置MaximizedBounds的位置:
Rectangle rect = Screen.FromHandle(this.Handle).WorkingArea; rect.Location = new Point(0, 0); this.MaximizedBounds = rect; this.WindowState = FormWindowState.Maximized;
我不擅长解释,但这是我用来最大化或全屏显示不会掩盖任务栏的winforms的代码。 希望能帮助到你。 ^^
private void Form_Load(object sender, EventArgs e) { this.Height = Screen.PrimaryScreen.WorkingArea.Height; this.Width = Screen.PrimaryScreen.WorkingArea.Width; this.Location = Screen.PrimaryScreen.WorkingArea.Location; }
如果要使用WindowState = Maximized;
,您应首先指明MaximizedBounds
属性最大化的表单的大小限制…
例:
MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea; WindowState = FormWindowState.Maximized;
您将表单的大小限制在作为显示器桌面区域的工作区域的哪个位置
如果最大化不是您正在寻找的,那么您需要通过检查任务栏的位置和大小来自己计算窗口大小:
发现出大小和位置,最任务栏
尝试不使用FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
和评论行像:
上述就是C#学习教程:全屏模式,但不要覆盖任务栏分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load( object sender, EventArgs e ) { // FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; Left = Top = 0; Width = Screen.PrimaryScreen.WorkingArea.Width; Height = Screen.PrimaryScreen.WorkingArea.Height; } }
private void frmGateEntry_Load(object sender, EventArgs e) { // set default start position to manual this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; // set position and size to the Form. this.Bounds = Screen.PrimaryScreen.WorkingArea; }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1008299.html