禁用退出/关闭按钮

本文关键字:关闭按钮 退出 | 更新日期: 2023-09-27 18:10:24

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

我一直在四处寻找,找到了下面的解决方案。但这只适用于Windows窗体!

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

禁用退出/关闭按钮

在wpf这个事件称为关闭:

public Window4()
    {
        InitializeComponent();
        this.Closing += new System.ComponentModel.CancelEventHandler(Window4_Closing);
    }
    void Window4_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true;
    }

您需要实现一个windows钩子来完成这一点。