Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Hiding a dialog without closing it

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Wong - 25 Dec 2005 09:50 GMT
Hi,

I am desperate searching for an answer to this problem.
I have shown a dialog (using ShowDialog) in my main form.

As I'm using a virtual desktop, I'm able to switch to another desktop
(which will hide or show the dialog and main form, depending if we are
leaving or coming back to that desktop).

The problem here is that when I leave the dialog open and switch away
and back again, the dialog closes, and the code following ShowDialog is
run, which is not the correct behavior.

This doesn't occur if I use MessageBox.Show

I tried to do a e.Cancel = true in the closing event of the dialog, but
it doesn't work at all.

Any idea?
Tim_Mac - 28 Dec 2005 23:11 GMT
hi Michael,
what kind of virtual desktop are you using?
it sounds like a problem with the desktop switching if it causes an open
Dialog to be closed.  does it happen if you stay in the current desktop, and
just switch between applications using Alt-Tab?

tim
--------------------------
blog: http://tim.mackey.ie
Michael Wong - 29 Dec 2005 01:39 GMT
Hi Tim,

I was desperate waiting for an answer.

The virtual desktop is an open-source one, so I could get the source
code an took a look at the switching process.

VirtuaWin: http://virtuawin.sourceforge.net

Apparently, when switching the desktop, all it does is hiding the main
window, and then all pop-up window (which is the dialog I suppose).

I'll try to hide the dialog manually and see what happens.

If any idea, please, let me know.

Thanks a lot

Michael

> hi Michael,
> what kind of virtual desktop are you using?
[quoted text clipped - 5 lines]
> --------------------------
> blog: http://tim.mackey.ie
JCM - 15 Mar 2006 11:34 GMT
Hi,
I experirment a similar problem, but not only with popup child window. It
seems  that some forms (all deriving from Windows.Forms.form class) interpret
the WS_SHOWWINDOW(false) message as a cancel event. But not all of them.
As i can modify the target forms, i found a wondering workaround, which
consists to shortcut the HIDE message ( 0x0018 whith wparam == 0) in
overriden WndProc of the form, that is to say  to return directly.
What a surprise when i see my target form disapear  and  come back when asked!
I'm searching  a rationnal explication... and a way to avoid this not
satisfying workaround.
Thanks

> Hi Tim,
>
[quoted text clipped - 25 lines]
> > --------------------------
> > blog: http://tim.mackey.ie
Kevin Spencer - 15 Mar 2006 15:13 GMT
If the dialog is a System.Windows.Forms.Form, and you call ShowDialog() to
display it, setting the DialogResult of the form to anything but "None" will
hide it.

Signature

HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

> Hi,
> I experirment a similar problem, but not only with popup child window. It
[quoted text clipped - 41 lines]
>> > --------------------------
>> > blog: http://tim.mackey.ie
JCM - 16 Mar 2006 11:36 GMT
Hi,
Thanks, but not sure it will help. The pb is not to hide the window, but to
not close it while hiding. May be you suggest to put "DialogResult = none" in
constructor so that the further Hide message won't close the window... I'll
check.

After further investigations, i confirm it appends for windows open withs
"ShowDialog" method.
It seems these windows have no parent window... Some have a owner, but it
seems it's not enough.  Do you think it is a good reason?
Actually, I'm trying to put a parent window to a form... It is not as easy
as i thunk.
Thanks.
Kevin Spencer - 16 Mar 2006 13:35 GMT
Hi JCM,

First, let me assure you that it does not close by simply setting the
DialogResult. I know this from much experience.

Second, the "ShowDialog" method is overloaded. Several overloads allow you
to set the parent window. For example, you can pass "this" to it, if
launching it from a Form, or other windowed Control.

Signature

HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

> Hi,
> Thanks, but not sure it will help. The pb is not to hide the window, but
[quoted text clipped - 12 lines]
> as i thunk.
> Thanks.
JCM - 16 Mar 2006 16:13 GMT
Hi Kevin,
Thanks for help.
As i can see, the only parameter i can give to ShowDialog is the owner, not
the parent (I have only 2 possibilities... OK i will search again). If i call
showDialog with no parameter, the owner is correctly set also. But I am still
not able to set the correct parent control of my form.

When i use SetParent ( from User32 dll)  before ShowDialog, the application
hangs once the form is displayed. Documentation of SetParent tells i have to
refresh the UIState of both impacted window... I don't understand how i can
do this simply.
Thanks

> Hi JCM,
>
[quoted text clipped - 4 lines]
> to set the parent window. For example, you can pass "this" to it, if
> launching it from a Form, or other windowed Control.
Kevin Spencer - 16 Mar 2006 17:57 GMT
Hi JCM,

I'm a little confused. You said you wanted to hide a dialog without closing
it. In the System.Windows.Forms.Form class, you have a few properties that
can relate to another form:

Owner: This is the form that "owns" the form. It is generally used with
dialog boxes, but the business rules are basically that the owned form
minimizes and closes when the Owner does so, and that the owned form cannot
appear behind the owner.
Parent: This is inherited from Control, and indicates the Control which is
the Container for this control. This is not really relevant to this
discussion, unless I'm seriously missing something.
ParentForm: This is the MdiParent of the form, when used in an MDI
interface. It is the Form which contains the form. The containing Form must
have IsMdiContainer set to true to use this.

However, as you can see, only Owner is relevant to a dialog box, which is a
window that pops up *outside* of the Form that spawned it. Only Owner is
really relevant. The Owner gives the dialog box access to the Form that
spawned it, and the Form which spawned it is almost always the form in which
the dialog box is referenced, so it can reference the spawned form via its
instance name.

A Form can also add a form to its "OwnedForms" Collection, by using the
"AddOwnedForm" method. This way, the dialog box is always owned by the
parent Form unless otherwise specified.

Signature

HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

> Hi Kevin,
> Thanks for help.
[quoted text clipped - 24 lines]
>> to set the parent window. For example, you can pass "this" to it, if
>> launching it from a Form, or other windowed Control.
JCM - 17 Mar 2006 08:38 GMT
Thanks Kevin,
That way, things are clearer for me. (about Owner/Parent differences)
Anyway, i still have the pb Michael Wong reported at the beginning of that
topic: While hiding a C# modal dialog box, it is destroyed.
I focused on Parent parameter because C++ modal dialog boxes have both owner
& parent window set with the handle of spawning application window. And these
windows are not destroyed while hided...
I'm looking for a way to reproduce in C# the behavior  of C++ dialog boxes.

Kenavo

> Hi JCM,
>
[quoted text clipped - 52 lines]
> >> to set the parent window. For example, you can pass "this" to it, if
> >> launching it from a Form, or other windowed Control.
Kevin Spencer - 17 Mar 2006 12:58 GMT
The correct way to hide it is to set the DialogResult.

Signature

HTH,

Kevin Spencer
Microsoft MVP
.Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

> Thanks Kevin,
> That way, things are clearer for me. (about Owner/Parent differences)
[quoted text clipped - 76 lines]
>> >> to set the parent window. For example, you can pass "this" to it, if
>> >> launching it from a Form, or other windowed Control.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.