单击红色关闭(x)按钮和调用.Close()之间有什么区别?

时间:2015-08-17 18:08:02

标签: c# winforms

我有一个winforms应用程序,在我的应用程序中,我有一个我创建的自定义表单。此自定义来自右上角的默认关闭,最小化和最大化按钮。如果我使用默认的红色x按钮关闭表单,它会正常关闭没有问题。但是,如果我尝试通过在窗体上调用.Close()来关闭窗体,则会抛出未处理的InvalidOperationException异常。

调用.Close()和单击该按钮有什么区别?为什么单击按钮工作正常,但调用.Close()会抛出异常?

1 个答案:

答案 0 :(得分:1)

您可以使用<form name="editview"> <input type="checkbox" id="edit_1" name="check1" class="edit"> <input type="checkbox" id="edit_2" name="check2" class="edit" disabled="disabled" checked="checked"> <input type="checkbox" id="edit_3" name="check3" class="edit" disabled="disabled"> <input type="checkbox" id="edit_4" name="check4" class="edit"> <input type="button" class="button" value="Select All" onclick="CheckUncheckAllAndExcludeDisabledByClass(this,'edit')" title="Select all: items."> <input type="checkbox" id="view_5" name="check5" class="view"> <input type="checkbox" id="view_6" name="check6" class="view" disabled="disabled" checked="checked"> <input type="checkbox" id="view_7" name="check7" class="view" disabled="disabled"> <input type="checkbox" id="view_8" name="check8" class="view"> <input type="button" class="button" value="Select All" onclick="CheckUncheckAllAndExcludeDisabledByClass(this,'view')" title="Select all: items."> </form> checked = true; function CheckUncheckAllAndExcludeDisabledByClass(theElement,theCheckBoxClass) { var checks = document.querySelectorAll('.' + theCheckBoxClass); for (var i = 0; i < checks.length; i++) { var check = checks[i]; if (!check.disabled) { check.checked = checked; } } checked = !checked; } 来记录窗口消息。

自: http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Form.cs,b6605a5b113b45f7

TOOLS->Spy++方法调用:

Form.Close()

此外,尝试搜索异常消息: https://www.google.com/search?q=Form+C%23+A+first+chance+exception+of+type++webbrowser&ie=utf-8&oe=utf-8

想出了这个链接:

C# : "A first chance exception of type 'System.InvalidOperationException'"