show or showdialog() difference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dim f As New SelectBuilding
f.Show()
f.ShowDialog()

hi what is the difference between f.show()
and f.showdialog()

which one takes more memory more time and performance
give me some difference
and where exactly can used this type

thanks
 
None of what you mention should be used as the criteria for choosing one
over the other.

One shows forms modally and the other doesn't. There are different
characteristics with usage of one over the other but your decision on which
one to use should be based solely on whether you need to show another form
and block execution until that form returns, or whether you don't.

Please search googlegroups for more on these two methods after you do what
you should be doing for any method you are not familiar: look it upon msdn.

Cheers
Daniel
 
There is more to it than that. A modal form can only exit by closing, which
disposes of it. If you have a large application with lots of forms, that is
an unacceptable overhead.
 
Not sure what point you're trying to make here. All forms are exited by
closing, not just modal forms. Closing a Modal form does *not* Dispose it -
that's inherent behavior of modal forms. Using them in large applications
is not unacceptable, nor does it require any more overhead than a non modal
form. You simply have to understand how each works and what the lifetime
implications of each are.

-Chris
 
Sorry, I don't see your point. Can you describe a scenario where you had to
switch from using ShowDialog to Show and what memory savings you got?

Cheers
Daniel
 
I was thinking of the CancelEventArgs.Cancel flag. According to the docs,
the Form.Close method *does* dispose of the form, unless this flag is set.
Are you saying that I can set this flag in the Closing event of a modal
form, and still exit the form? I have not tried that.

I was not referring to memory, but to performance. If you have a large form,
it can take several seconds to open it. I consider that to be unacceptable,
if it occurs every time you show the form.
 
So your argument is that closing a modal form keeps it in memory for reuse
but closing a non-modal one doesn't? So what prevents you from hiding the
non-modal form instead of closing and making it visible again when you want
it? Or even sending it to the back and then bringing it to the front?

Cheers
Daniel
 
That is not what I said. On the contrary, I am saying that you cannot reuse
a modal form. Hiding non-modal forms is precisely what I do. But the OK
button generates a Closing event, hence the Cancel flag. Having more than
one form visible is not a good idea.
 
So have you devised a mechanism for making the non-modal form behave like a
modal one?

If not, then you are agreeing that you didn't have a need for a modal form
in the first place (and hence that is what you based your decision on).

If you have, I'd be interested in seeing the comparison between the two
approaches (ShowDialog vs Show with modality achieved via code) and how you
think you benefited perf-wise.

BTW, why do you think a modal form cannot be reused?

Cheers
Daniel
 
The reason I think that modal forms are not reusable, is that they remain
modal until they are closed, at which point they are disposed of. Am I wrong
about this?
 
Given the .NET CF (one visible form at a time) what's the difference
between modal and non-modal anyway?
 
First, you assume that just becasue your device behaves that way that all
do. That's an incorrect assumption. All the devices I use I can see more
that one form at a time, whether they are modal or not. I don't develop (or
rarely anyway) for Pocket PC.

Second, modal and non-modal forms behave differently in a few aspects.
Modal forms block calling execution until a result is returned and they
prevent the user from switching to another Form.

-Chris
 
On the Pocket PC with the .Net Compact Framework 1.0 (I cannot say for
sure for 2.0), Dialogs that are called with ShowDialog CANNOT be
reused. The window handle is disposed of when they are closed.
 
Back
Top