Bug 5040 - me.hide() triggers FormClosing with CloseReason = CloseReason.UserClosing
Summary: me.hide() triggers FormClosing with CloseReason = CloseReason.UserClosing
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: 2.10.x
Hardware: PC Linux
: Lowest normal
Target Milestone: Community
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-05-12 02:21 UTC by Simon
Modified: 2017-09-01 11:55 UTC (History)
3 users (show)

Tags: mono-community
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 5040 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Simon 2012-05-12 02:21:18 UTC
I've never submitted a bug report here, so I hope this is the right place and there's enough information.


On windows, calling Me.Hide() within a form fires a FormClosing event with CloseReason set to CloseReason.None

On mono (tested on 2.4 AND 2.10), the exact same code fires the FormClosing event with CloseReason set to CloseReason.UserClosing, even though the form.hide() was called in code and had nothing to do with user actions.

I'm using visualbasic code compiled on VB2008.



Sample Code:



Private Sub cmdNext_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNext.Click
	
         If CurrentPage = TabControl1.TabPages.Count - 1 Then
            cLog.LogEvent("Clicked Finish in Project Wizard")
            Me.DialogResult = Windows.Forms.DialogResult.OK
            cLog.LogEvent("Dialogresult: " & Me.DialogResult)
            Me.Hide() ' Triggers FormClosing with different parameters on Win/Mono
         Else
            CurrentPage = CurrentPage + 1
            Call DisplayCurrentPage()
         End If
		
End Sub



Private Sub frmProjectWizard_FormClosing(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

      If eventArgs.CloseReason = System.Windows.Forms.CloseReason.UserClosing Then
         cLog.AddAction("Wizard form closed")
         DialogResult = Windows.Forms.DialogResult.Cancel
      End If
		
   End Sub



Log result under Mono:

14:18:35, Running New Project Wizard
14:18:44, Clicked Finish in Project Wizard
14:18:44, Wizard form closed
-- this Last line is repeated thousands of times until a SigSegv error occurs. Note that the line 'cLog.LogEvent("Dialogresult: " & Me.DialogResult)' is never reached



Log result under Windows (Exactly the same sequence of user actions)

14:12:41, Running New Project Wizard
14:12:50, Clicked Finish in Project Wizard
14:12:50, Dialogresult: 1
14:12:50, Project wizard completed
Comment 1 Simon 2012-05-12 02:23:01 UTC
Re-reading the report, I'm wondering whether setting DialogResult = Windows.Forms.DialogResult.OK is actually firing the FormClosing event?
Comment 2 Zoltan Varga 2012-05-13 09:35:39 UTC
-> winforms.
Comment 3 Simon 2012-07-23 21:15:35 UTC
This is the issue (Form.cs).  Copy and paste from Mono 2.10.9, including the comment from the source code where someone else is obviously aware of the problem.

if (dialog_result != DialogResult.None && is_modal)
    RaiseCloseEvents (false, false); // .Net doesn't send WM_CLOSE here.
			

On .Net, setting dialogresult on a model form does not trigger a close event. Dialogresult is treated like a variable on .Net, not a function.