[Mono-winforms-list] Modal form strange behaviour (disabled open forms)

AlexR meddows at mail.ru
Thu May 24 14:22:08 UTC 2012


Hello.
The problem is that when you call ShowDialog all the rest open forms are
getting disabled.
And when you hide modal form, all forms remain disabled.
What is the best way to fix that? Maybe just enumerate all opened forms
(Application.OpenForms) and set Enabled = true? Is this correct way which
won't causes any other bugs?

To reproduce the issue use the following code.
Run the app. Click the button. It'll show modal form. Then click the button
on modal form.
It'll hide the modal form. And main form remains disabled (button can't be
clicked and form can't be closed).

using System;
using System.Windows.Forms;

namespace ModalFormBug
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var form = new Form();
			var btn = new Button();
			btn.Click += OnButtonClick;
			form.Controls.Add(btn);
			
			Application.Run(form);
		}
		
		static void OnButtonClick(object sender, EventArgs args)
		{
			var form = new Form();
			var btn = new Button();
			btn.Click += (x, y) => form.Hide();
			form.Controls.Add(btn);
			form.ShowDialog();
		}
	}
}

--
View this message in context: http://mono.1490590.n4.nabble.com/Modal-form-strange-behaviour-disabled-open-forms-tp4649529.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.


More information about the Mono-winforms-list mailing list