簡體   English   中英

如何阻止 Powershell WPF 表單關閉

[英]How to stop a Powershell WPF Form from closing

我一直在嘗試實現一種方法來阻止用戶在 Powershell 中手動單擊我的 WPF 表單上的紅色“x”。 在線研究表明,最好的方法是使用表單關閉事件,停止事件並隱藏表單。 在 C# 中似乎有很多方法可以這樣做,但我似乎找不到任何適用於 Powershell 的方法。 例如,可以在 C# 中使用這樣的東西。

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true;
        this.Visibility = Visibility.Hidden;
    } 

有什么可以在 Powershell 中使用的等價物嗎?

Powershell 中關閉表單的事件是add_Closing ,但我不知道如何停止關閉表單。

對於任何感興趣的人,這就是它的簡單:

 $form.add_closing
    ({
        $_.cancel = $true 
    })

只是一個簡短的說明,如果您使用 WPF 表單,這將起作用。 如果您使用的是 WinForm,則必須使用[System.Windows.Forms.FormClosingEventHandler]使其工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM