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

P

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
 
P

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
 
P

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
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top