FormClosingEventArgs错误?

时间:2016-03-03 18:03:32

标签: c#

public void AltF4(object sender, FormClosingEventArgs e)
{
    e.Cancel = true;
    base.OnClosing(e);
}

它告诉我Object没有OnClosing的定义。谁能告诉我为什么?

1 个答案:

答案 0 :(得分:0)

如评论中所述,您可以尝试以下方式:

protected override void OnFormClosing(FormClosingEventArgs e) 
{
    if (e.CloseReason != CloseReason.WindowsShutDown 
    && e.CloseReason != CloseReason.ApplicationExitCall 
    && e.CloseReason != CloseReason.FormOwnerClosing )
    {
        e.Cancel = true;
    }
    base.OnFormClosing(e);
}

希望这可能会有所帮助。