PublicError

Hi

In my main-form I open another form using:

new AnotherForm().ShowDialog();

AnotherForm has these properties set to "false":

- MaximizeBox

- MinimizeBox

- ShowIcon

- ShowInTaskbar

Now if I open this "AnotherForm" using the code above, is it then possible to minimize

both forms (mainform and the opened AnotherForm), by pressing the taskbar-item (that belongs to the main-form)



Re: Windows Forms General Minimize program when a modal dialog is shown?

vtortola

Handle the 'SizeChanged' main form event, and then:

Code Snippet

private void Form1_SizeChanged(object sender, EventArgs e)

{

if (this.WindowState == FormWindowState.Minimized)

{

anotherForm.WindowState = FormWindowState.Minimized;

}

}

Regards.






Re: Windows Forms General Minimize program when a modal dialog is shown?

nobugz

No, calling ShowDialog() causes the main form to be disabled. Which disables the system menu for the taskbar button too. The only alternative is to display the form with Show(this), that ensures the "dialog" stays on top of its parent and automatically minimizes the dialog when the parent gets minimized.

Off topic for the BCL forum, moved to Windows Forms General.





Re: Windows Forms General Minimize program when a modal dialog is shown?

PublicError

Hi nobugz

Isn't that a kind of an ugly solution Wink

Because, then the AnotherForm is not modal. :/

I've seen this in other softwares.

There is no "real" solution using the .NET framework :/





Re: Windows Forms General Minimize program when a modal dialog is shown?

nobugz

Nope, as soon as you minimize a form shown with ShowDialog() it will close. You can simulate modality by disabling all controls and subscribing to the form's FormClosing event, so you know when you user dismissed it. Re-enable all controls and use the form's info in the FormClosing event handler.