2016-03-01 125 views
1

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

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

是否有任何相當於我可以在Powershell中使用的東西?

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

回答

1

任何有興趣,這是多麼簡單是:

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

只是一個快速的注意,如果您使用的是WPF的形​​式,這將工作。如果您使用WinForm,則必須使用[System.Windows.Forms.FormClosingEventHandler]才能使其工作。