dotnet / dotnet/dotnet-api-docs

Require to update Remark info for Form.ShowDialog method

Open
#9,644 0 comments 0 reactions 0 assignees View on GitHub
area-WinForms Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

---
**Issue moved from MicrosoftDocs/feedback#3988**
- Please respond to @Eudora-Li01.

---

_From @Eudora-Li01 on Wednesday, January 31, 2024 6:40:01 AM_

**Is your feature request related to a problem? Please describe.**
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.showdialog?view=windowsdesktop-8.0#system-windows-forms-form-showdialog(system-windows-forms-iwin32window)
This doc clarifies that when a form is displayed as a modal dialog box, clicking the Close button (the button with an X at the upper-right corner of the form) causes the form to be hidden and the [DialogResult](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.dialogresult?view=windowsdesktop-8.0) property to be set to DialogResult.Cancel. Unlike modeless forms, the [Close](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.close?view=windowsdesktop-8.0) method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the [DialogResult](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.dialogresult?view=windowsdesktop-8.0) property. **Instead the form is hidden and can be shown again without creating a new instance of the dialog box.**

But actually, you can see from the attached WinForms project (C#, .NET 8.0), that this is not the case. Instead, the Form_Load event is fired on every ShowDialog. This means the code in Form_Load runs every time the form is shown though it has already been loaded.
[WinFormsApp1.zip](https://github.com/MicrosoftDocs/feedback/files/14108026/WinFormsApp1.zip)
![image](https://github.com/MicrosoftDocs/feedback/assets/130345015/395344e6-cbfb-49b0-bb96-d2aaf20dd7f3)

**Describe the solution you'd like**
Please add more info after above statement:
However, Form_Load will trigger AFAIK when for whatever reason the handle got created, recreated or the Form was previously shown as a modal Dialog.

**Describe alternatives you've considered**
N/A

**Additional context**
N/A

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.