【问题标题】:Hide one desktop window or disable closing button - Windows Desktop App隐藏一个桌面窗口或禁用关闭按钮 - Windows 桌面应用程序
【发布时间】:2015-09-10 15:18:05
【问题描述】:

我正在创建一个在 Windows 8.1 Pro 上运行的 Windows 桌面应用程序。

我可以使用此属性以编程方式将其最小化:

WindowState.Minimized;

有没有办法完全隐藏它,或者禁止用户关闭它?

我尝试了所有these StackOverflow solutions,但是

它们对我不起作用。

我试过了

private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);

然后我尝试将以下方法添加到我的 windows 类中

protected override void OnClosing(CancelEventArgs e)
{
   base.OnClosing(e);
   e.Cancel = true;
}

我尝试了这个属性

        WindowStyle = WindowStyle.None;

仍然没有运气。

我怎样才能得到它?

我正在使用 VS2015 和 WPF

【问题讨论】:

  • 在 XAML 中使用 <Window ... WindowStyle="None">。添加您自己的按钮。
  • 已经试过了,但是不行
  • 不可能,我做了几次,总是很好。工商管理硕士你有一些在运行时禁用它的窗口逻辑。 msdn.microsoft.com/en-us/library/…

标签: c# wpf windows desktop-application


【解决方案1】:

只需在您的 xaml 中将 ShowInTaskBar 属性设置为 False-

ShowInTaskbar="False"

在 c# 代码中,只需在程序初始化时隐藏你的窗口:

  public MainWindow()
    {
        InitializeComponent();
        this.Hide();
    }

祝你好运。

【讨论】:

  • 这是做什么的?
  • 它不会改变任何东西
  • @eeadev 什么意思没有改变?
猜你喜欢
  • 1970-01-01
  • 2015-02-23
  • 1970-01-01
  • 2010-12-21
  • 2011-06-01
  • 1970-01-01
  • 2011-02-15
  • 2012-05-04
  • 1970-01-01
相关资源
最近更新 更多