【问题标题】:C# WPF Disable the exit/close button [duplicate]C#WPF禁用退出/关闭按钮[重复]
【发布时间】:2013-04-14 12:20:55
【问题描述】:

是否可以禁用 WPF 表单中的关闭按钮? 如何禁用关闭按钮?

我一直在寻找并找到以下解决方案。但这仅适用于 Windows 窗体!

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
      e.Cancel = true;
}

【问题讨论】:

标签: c# wpf


【解决方案1】:

在 wpf 中,此事件称为 Closing:

public Window4()
    {
        InitializeComponent();
        this.Closing += new System.ComponentModel.CancelEventHandler(Window4_Closing);
    }

    void Window4_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true;
    }

【讨论】:

    【解决方案2】:

    您需要实现一个 Windows 挂钩来完成此操作。详情请见this MSDN post

    【讨论】:

      猜你喜欢
      • 2017-07-10
      • 2011-08-26
      • 1970-01-01
      • 2019-03-29
      • 2013-07-31
      • 1970-01-01
      • 2011-04-06
      • 2010-09-10
      • 1970-01-01
      相关资源
      最近更新 更多