Hi Bragadiru,
this is normal because your UI thread stops in the ShowDialog method call.
No code will be executed until you close the modal form. The only place
where you can do something to workaround the problem is the modal form. I
assume that the modal form is yours; not some common Windows dialog. If it
is the latter that's it. There is not much you can do about it, unless
probably you can use some hooks and stuff.
So I assume you have control over the dialog code.
First step is to minimize the main form before you open the dialog.
Second to show the dialog. At this point it will show minimized.
And the third step is to return back the dialog to its normal state from the
code of the dialog itself.
Here is the code
--- in the main form ---
using(Form2 dlg = new Form2())
{
this.WindowState = FormWindowState.Minimized;
dlg.ShowDialog(this);
}
-- in the dialog --
//overide OnLoad (the same could be done if you hook dialogs Load event in
the main form. Common Windows' dialogs doesn't have that event, though)
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
this.Activate();
}
this will return back the dialog to its noraml state.
That has the annoying side effect that you see that animation that Windows
does when minimizes and maximizes windows.
To workaround this I'd suggest to hide the main form before minimizing it.
Then if you want to have your main form visible on the taskbar show it again
after minimization of not show it after the dialog is closed.
The code for hidden main form would be
using(Form2 dlg = new Form2())
{
this.Hide();
this.WindowState = FormWindowState.Minimized;
dlg.ShowDialog(this);
this.WindowsState = FormWindowsState.Normal;
this.Show();
}
Now we got rid of the windows animations, but got another not less annoying
problem; when hide and show forms the taskbar changes, but I feel like it is
better then before.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
Bragadiru said:
Hi,
Here is code from my main form1 application :
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
ModalForm modalForm = new ModalForm();
modalForm.ShowDialog();
modalForm.Dispose();
}
My main form has only 1 button. When it is pressed, a dummy modal form is
opened.
Now, I CANNOT minimize main form untill modal form is closed. I need a
workaround for this feature. If you can do it in Visual FoxPro 6.0, why
not
in newest Studio .NET ???
Also, I ment AutoHide Taskbar, sorry.
Thanks,
Adi
Stoitcho Goutsev (100) said:
Hi Bragadiru,
Frankly, I don understand your issues, but yes, you cannot minimize the
owner of the dialog. If you do that the dialog will follow the owner
and
is
going to minimize as well.
When using AutoHide Toolbars on windows XP - the user cannot access
them
unless he minimizes or resizes the main window...but he can't do that
What are those toolbars? Are they third party controls or you meant
"Taskbar" here?
Either ways I'm not sure what that means, but as you said instead of
minimizing you can change the size. You can do that. I guess you want
to
do
that form the code of a modal window
In this case show the dialog like the following snippet
using(Form2 dlg = new Form2())
{
dlg.ShowDialog(this);
}
and in a dialog's code when you want to change the main form size just do
Size origSize = this.Owner.Size;
this.Owner.Size = new Size(origSize.Width-1, origSize.Height-1);
this.Owner.Size = origSize;
If it doesn't help I'd suggest to post some working sample that demostrates
your issues
--
Stoitcho Goutsev (100) [C# MVP]
Hi,
My mainform is modeless, has mdiChilds, but I need to open modal forms
from
mdiChild => I cannot minimize mainform when a modal form is opened.
I understand that's a "feature" = You cannot minimize applications that
show
a modal dialog.
ANYWAY, there is any workaround to this problem ? I cannot make the
form
modeless.
When using AutoHide Toolbars on windows XP - the user cannot access
them
unless he minimizes or resizes the main window...but he can't do that
without saving his data and closing one of these MODAL forms. (Very, very
annoying).
It was working very nice in Visual FoxPro 6.0 and now in Visual Studio
.NET
2003 cannot be done ????
Thanks for any advice,
Adi