Home All Groups Group Topic Archive Search About

How do I open an nonmodal owned form over a mdi container ?

Author
2 Feb 2006 12:46 PM
pamelafluente
Hi guys I am puzzed (???) with a probably stupid problem (VB2003). I
must be doing something dumb ...

I want to open a owned form (must *not* be mdi child) over an Mdi
Container, when the Mdi container starts.

I have a small demo program made of: Form1, Form2 (empty) and a
"StartProgram" class
which contain the following code. The startup object is set to be: Sub
Main

in case you want the source I have place a tiny file here:
http://cam70.sta.uniroma1.it/TechnicalPreview/mditrial.zip

'-----------------------------------------------------------

Public Class Form1
    Inherits System.Windows.Forms.Form

'#Region " Windows Form Designer generated code "
'#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Me.IsMdiContainer = True
        Me.WindowState = FormWindowState.Maximized

        Me.ShowForm2_NonModal()

    End Sub

    Sub ShowForm2_NonModal()

        Dim Form2 As New Form2
        With Form2
            .Owner = Me
            .Show()
        End With

    End Sub

End Class
'-----------------------------------------------------------


'-----------------------------------------------------------
Public Class Form2
    Inherits System.Windows.Forms.Form

'#Region " Windows Form Designer generated code "
'#End Region

End Class
'-----------------------------------------------------------


'-----------------------------------------------------------
Public Class StartProgram

    Shared Function Main(ByVal Argomenti() As String) As Integer

        'Get arguments
        For Each Argument As String In Argomenti
            MsgBox("Found command argument: " & Argument)
        Next Argument

        'Start main application
        Dim Form1 As New Form1
        With Form1
            .ShowDialog()
            .Dispose()
        End With

        'Exit returning exit code
        Return 0

    End Function

End Class
'-----------------------------------------------------------

So the Sub Main calles a MDI form (Form1). When the MDI form opens I
also want to open on top of it another owned (not mdi children) form
(Form2) and I want to to that in NONMODAL way.

This does not seem to work because the owned form Form2 remains blocked
in the mdi Container.

My question: How do I fix this ?

Note that: changing .ShowDialog() to would work, but I want Form2
opened in a * non * modal state.



Thank you in advance for any help,

-Pam

Author
2 Feb 2006 12:59 PM
Armin Zingler
<pamelaflue***@libero.it> schrieb
>        With Form1
>            .ShowDialog()
>            .Dispose()
>        End With

Replace this code in Sub Main by

            application.run (Form1)



Armin
Author
2 Feb 2006 3:19 PM
pamelafluente
Hi Armin.... thank you for your help.  That solution I have abandoned
some time ago, because I noticed that, if I do that - when there is an
error in the program - the debugger is NO MORE able to go to the line
where the error is (it merely says the file and line where occurred),
which is very very annoying.

Actually, I do not understand why my way does not work. That's really
strange, because if the Me.ShowForm2_NonModal() is called AFTER loading
everything is fine. This doesn't make much sense to me.

Also, I do not understand why if I use the method You suggest, the
debugger is no more able to go to an error line, when an error occurs.
I can vaguely imagine the reason, infact the same happen when an error
occurs, for instance, on a timer event or on a Drag Drop: so must be
related to the fact that it is within a thread different from the main
one. Can you fix this behavour ???

All this is very very annoying...

-PAM
Author
2 Feb 2006 3:47 PM
pamelafluente
To see that it would work if called after LOAD try this. Place a timer
(Timer1) and replace:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Me.IsMdiContainer = True
        Me.WindowState = FormWindowState.Maximized

        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 1

    End Sub

and add this one:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
        Me.ShowForm2_NonModal()
        Me.Timer1.Enabled = False
        Me.Timer1.Dispose()
    End Sub

See what happen, Amazing eh? I just can't understand why I doesn't want
it during the load ????

-Pam
Author
2 Feb 2006 3:49 PM
Armin Zingler
<pamelaflue***@libero.it> schrieb
>
> Hi Armin.... thank you for your help.  That solution I have
> abandoned some time ago, because I noticed that, if I do that - when
> there is an error in the program - the debugger is NO MORE able to
> go to the line where the error is (it merely says the file and line
> where occurred), which is very very annoying.

Hmmm...

> Actually, I do not understand why my way does not work. That's
> really strange, because if the Me.ShowForm2_NonModal() is called
> AFTER loading everything is fine. This doesn't make much sense to
> me.

It was never allowed to show a non-modal Form after a modal Form is
displayed.

> Also, I do not understand why if I use the method You suggest, the
> debugger is no more able to go to an error line, when an error
> occurs. I can vaguely imagine the reason, infact the same happen
> when an error occurs, for instance, on a timer event or on a Drag
> Drop: so must be related to the fact that it is within a thread
> different from the main one. Can you fix this behavour ???
>
> All this is very very annoying...


This is indeed a (different) problem. I currently don't know how to solve
it.

I know the problem with the exception in a Timer's Tick event handler: The
exception is not caught but the "JIT debugger" message occurs. This is a bug
fixed in version 2005. Hopefully it will also be fixed in the next VS 2003
SP.


Armin
Author
2 Feb 2006 4:08 PM
pamelafluente
Armin Zingler ha scritto:
> It was never allowed to show a non-modal Form after a modal Form is
> displayed.

yes on the same thread. See this:

http://cam70.sta.uniroma1.it/TechnicalPreview/mditrial2.zip

-Pam
Author
2 Feb 2006 4:25 PM
Armin Zingler
<pamelaflue***@libero.it> schrieb im Newsbeitrag
news:1138896533.736719.300400@f14g2000cwb.googlegroups.com...
>
> Armin Zingler ha scritto:
>> It was never allowed to show a non-modal Form after a modal Form is
>> displayed.
>
> yes on the same thread. See this:
>
> http://cam70.sta.uniroma1.it/TechnicalPreview/mditrial2.zip


Sorry, I was wrong. Back in VB6, it was not allowed.

Well, I still wouldn't use ShowDialog for showing an MDI container.


Armin