Non-full screen and fullscreen dialogs

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Juan Pedro Gonzalez (the_duke_at_terra.es)
Date: 04/12/04


Date: Mon, 12 Apr 2004 20:29:43 +0200

Hi,

I've been trying to do a walk around for dialogs.

I'm using VB .NET 2003. I found out that the ShowDialog wasn't working when
I called it. It seems the dialog would stay on the background. My small
workarround for full screen dialogs is as follows:

*FULLSCREEN DIALOGS*

I decleare a Private variable for the form class:

Private mvar_ParentForm as Form

Then I create a new function that overrides the ShowDialog in the form I
wish to visualize as a dialog as follows:

Public Shadows Function ShowDialog(ByRef ParentForm as Form) As
Windows.Forms.DialogResult
    Me.mvar_ParentForm = ParentForm
    Me.BringToFront()
    Return MyBase.ShowDialog()
End Function

The last step is another walkarround so the main application form gets shown
if I close the dialog (The dialog form is called FrmDialog):

Private Sub FrmDialog_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
     Me.SendToBack()
     Me.mvar_ParentForm.BringToFront()
End Sub

This works right for Full screen dialogs, although I don't really like what
I see on the "Running Aplications" window... It shows two applications: One
of them is my real aplication an the other is the dialog form. If I activate
the real aplication I get a blocked form. The last work arround was done due
to this effect: when I activated the Dialog form and I pressed OK the
application form wouldn't show up. Is there a way to get rid of this effect?
I mean merging both "applications" into one application?

Note: asigning the parent form won't work as I get a blocked dialog window
with an innactive bar.

*NON-FULL SCREEN DIALOGS*

It seems this is a really common question... Here's my work around for this
kinds of dialogs...

The work arround I did here is as follows (Again everything is done in the
form that will act as a dialog):

I changed the Form's New (Comments are in spanish as it's my natural
language):

Public Sub New(Optional ByVal ParentForm As Form = Nothing)
     MyBase.New()

     Me.Parent = ParentForm

     'El Diseñador de Windows Forms requiere esta llamada.
     InitializeComponent()

     'Agregar cualquier inicialización después de la llamada a
InitializeComponent()
End Sub

It seems important to asign the parent before initializing the components.
The next step would be overriding the ShowDialog:

Next step: Override the de ShowDialog as follows:

Public Shadows Function ShowDialog() As Windows.Forms.DialogResult
    Me.Parent = Nothing
    Me.BringToFront()
    Return MyBase.ShowDialog()
End Function

You'll notice I assigned a parent for this form and now I'm setting it to
nothing... Well, there's an explanation to it: If I dont set the parent form
on New then I don't get a Non-full screen dialog, but if I don't reset this
value to nothing the I'll get a blocked form wich I won't be able to move or
click on any item of it. By setting it to nothing this problem dissapears
and I'll be able to use the form.

This walkarround will give a working non-full screen dialog but there's
still some points wich I'd like to get fixed and maybe someone can help with
it.

The first problem is that the title bar will be shown in a grey color
(inactive) although you can move it and interact with the controls on it.
Any ideas on how to get this fixed?

The second problem, wich is giving me a headache is the ok button. If the
form has the MinimizeButton set to true the "OK" button shows up correctly
but it won't interact with the user... if the minimizebutton is set to false
the ok button will appear displaced and won't let you interact, although
it's displaced because a hiden minimize button is there (and it will let you
minimize the dialog although it won't return a value)... If the controlbox
is set to false the ok button won't appear, but the "hidden" minimize button
will still be there.

If there's a way to get the "Ok" button image intro the "hidden minimize"
button, this walkarround could be tweaked to get a fully working non-full
screen dialog. Any one has any idea on how to do this? Another good way to
get it working would be trying to do some subclassing or something to get
the ok button to work with the minimizebox to true. Again asking for help
with this issue.

Greetings,

Juan



Relevant Pages

  • Re: Non-full screen and fullscreen dialogs
    ... > I've been trying to do a walk around for dialogs. ... > Then I create a new function that overrides the ShowDialog in the form I ... > It seems important to asign the parent before initializing the components. ... > Public Shadows Function ShowDialog() As Windows.Forms.DialogResult ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Non-full screen and fullscreen dialogs
    ... > I've been trying to do a walk around for dialogs. ... > Private Sub FrmDialog_Closing(ByVal sender As Object, ... > It seems important to asign the parent before initializing the components. ... > Public Shadows Function ShowDialog() As Windows.Forms.DialogResult ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Missing Link for CF Application Idle Timer
    ... dialogs, you have to use the SDF version of ShowDialog (in Application2 ... OpenNETCF Consulting ... Do I need to register or something to access it? ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Accessing class members ...
    ... The problem here could arise if dialogs are modeless; ... I see when this question is asked is someone trying either to modify controls in a parent ... class or reach into child windows to manipulate data, both of which are really bad ideas. ... and usually there is no other communication. ...
    (microsoft.public.vc.mfc)
  • Re: [OK] button vanishing in forms
    ... parent form from the user so that they cant interact with it. ... I haven't checked it with the Pocket PC ... why can't we use the ShowDialog? ... >>> ShowDialog is really inconsistent and should be deprecated in my opinion. ...
    (microsoft.public.dotnet.framework.compactframework)