命令this.WindowState = FormWindowState.Maximized后隐藏并锁定windows任务栏; [英] hide and lock windows taskbar after command this.WindowState = FormWindowState.Maximized;

查看:740
本文介绍了命令this.WindowState = FormWindowState.Maximized后隐藏并锁定windows任务栏;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

当命令(this.WindowState = FormWindowState.Maximized;)将被运行时,windows的任务栏将被隐藏和锁定。我必须按键盘的Windows键才能显示窗口任务栏。



我该怎么办?

谢谢

hello
when command (this.WindowState = FormWindowState.Maximized;) will be run , the taskbar of windows will be hide and lock. and i must press windows key of keyboard for show windows taskbar.

what should i do?
thanks

推荐答案

您可以使用此代码隐藏或显示TaskBar:
You can use this code to hide, or show, the TaskBar:
// required
using System.Runtime.InteropServices;

// in Form or Class scope
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int command);

private const int SW_HIDE = 0;
private const int SW_SHOW = 1;

private bool IsTaskBarShown = true;

private IntPtr TaskBarHWnd = FindWindow("Shell_TrayWnd", "");

private void setTaskBarState(bool isShown)
{
    // can't find a TaskBar : game-over
    if (TaskBarHWnd == null) return;

    IsTaskBarShown = isShown;

    if (IsTaskBarShown)
    {
        ShowWindow(TaskBarHWnd, SW_SHOW);
    }
    else
    {
        ShowWindow(TaskBarHWnd, SW_HIDE);
    }
}

// reason for this is discussed below
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (! IsTaskBarShown) setTaskBarState(true);
}

1。如果您隐藏TaskBar,它隐藏为global:如果用户切换到另一个应用程序,则没有TaskBar。如果你关闭你的应用程序,隐藏任务栏,它将保持隐藏。



没有知道当任务栏显示或隐藏时应用程序启动,我们可能没有意义改变其状态,并在用户关闭我们的应用程序时保持该更改状态生效。



在离开时做出刺在应用程序终止时隐藏的TaskBar,您可以看到在代码示例中创建了一个FormClosing EventHandler,确保在应用程序终止时TaskBar可见...但是,如果TaskBar被隐藏起来怎么办:显然这不是一个完整的解决方案。



2.如果按下Windows键,使用此技术隐藏TaskBar,开始菜单将弹出窗口,但没有任务栏。



所以:一个更强大的解决方案要求确定应用程序时TaskBar的状态开始,恢复那个状态......如果我们有陈在退出时......实现 的乐趣和荣耀归于OP。在确定TaskBars的实现方式以及它们是否可见时,您可以看到问题:[ ^ ]。



讨论:



对于设计来说,一般以阻止用户配置的方式使用Windows是一件好事;当然,也有一些例外,例如为专用的东西创建一个信息亭模式的应用程序;或者,为互联网租赁设施等事项创建特殊应用程序;或者,其他可能的安全相关目的。或者,防止孩子在使用适合儿童的计划时碰巧碰到钥匙。



在这种情况下,我们可以/应该问为什么用户不应该有权访问TaskBar,但仍然可以访问Windows开始菜单,并使用alt-Tab在应用程序之间切换。

1. If you hide the TaskBar, it's hidden "globally:" if the user switches to another application, there's no TaskBar. If you close your Application, with the TaskBar hidden, it will stay hidden.

Without knowing whether the TaskBar is shown or hidden when the Application starts, we might without meaning to change its state and leave that changed state in effect when the user closes our Application.

To make a "stab" at leaving the TaskBar hidden when the Application terminates, you can see that in the code example a FormClosing EventHandler was created that makes sure the TaskBar is visible when the Application terminates ... but, what if the TaskBar was hidden to begin with: clearly this is not a complete solution as is.

2. If you press the Windows Key, with the TaskBar hidden using this technique, the Start menu will pop-up, but no TaskBar.

So: a more "robust" solution would require determining the state of the TaskBar when the Application starts, and restoring that state ... if we had changed it ... on exit. The fun and glory of implementing that is left to the OP. You can get a smell of issues in determining what TaskBars are implemented, and whether they are visible, or not, here: [^].

Discussion:

In terms of design, it's generally not a good thing to lock-out the user from using Windows the way they have configured it; of course, there are exceptions like creating a kiosk-mode application for a dedicated something-or-other; or, creating special applications for things like internet rental facilities; or, other possible security-related purposes. Or, preventing a child from running amok hitting keys while using your whatever-for-children program.

In this case, we can/should ask why the user should not have access to the TaskBar, but still have access to the Windows Start Menu, and using alt-Tab to switch between Applications.


这篇关于命令this.WindowState = FormWindowState.Maximized后隐藏并锁定windows任务栏;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆