Modal dialogs hang up my program

  • Thread starter VBTricks.de.vu Webmaster
  • Start date
V

VBTricks.de.vu Webmaster

Hello there,

I've encountered some strange behaviour. I display modal dialogs (using
ShowDialog) called from my mainform.
This is how the mainform is displayed out of the main sub of a module:
[vb]
Public fMain As frmMain

Public Sub Main()
Try
fMain = New frmMain
System.Windows.Forms.Application.Run(fMain)
Catch ex As Exception ' line c
MsgBox(ex.Message)
End Try
End Sub
[/vb]
and the modal dialog in frmMain:
[vb]
Private Sub MnuExtrasSettingsClick(sender As System.Object, _
e As System.EventArgs)

Try
Dim fSettings As New frmSettings
If fSettings.ShowDialog(Me) = DialogResult.OK Then ' Line a
' settings changed, load anew
LoadSettings(False)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub ' Line b
[/vb]
The dialog appears, but when close the button (whether with the OK or
Cancel-Button), the dialog closes and my app, too. The exception handler
of the main module displays "An external component raised an exception".
When I debug the prog, Line a displays the dialog, but when I close it,
jumps to Line b, and then to Line c (first source).
What am I doing wrong? (Accept- and CancelButton-properties of
frmSettings and the DialogResult-properties of the buttons are set).

When I copy the source from MnuExtrasSettingsClick to a timer tick event
and call it from MnuExtrasSettingsClick (Timer.Enabled = True), the
program does not crash.

What's wrong? I just don't understand it.


Thanks in advance,

Stefan

--
___________________________________www.VBTricks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_____________________________________________________
 
K

Ken Tucker [MVP]

Hi,

I usually dont specify an owner when I use show dialog.

If fSettings.ShowDialog() = DialogResult.OK Then

Ken
---------------------
message Hello there,

I've encountered some strange behaviour. I display modal dialogs (using
ShowDialog) called from my mainform.
This is how the mainform is displayed out of the main sub of a module:
[vb]
Public fMain As frmMain

Public Sub Main()
Try
fMain = New frmMain
System.Windows.Forms.Application.Run(fMain)
Catch ex As Exception ' line c
MsgBox(ex.Message)
End Try
End Sub
[/vb]
and the modal dialog in frmMain:
[vb]
Private Sub MnuExtrasSettingsClick(sender As System.Object, _
e As System.EventArgs)

Try
Dim fSettings As New frmSettings
If fSettings.ShowDialog(Me) = DialogResult.OK Then ' Line a
' settings changed, load anew
LoadSettings(False)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub ' Line b
[/vb]
The dialog appears, but when close the button (whether with the OK or
Cancel-Button), the dialog closes and my app, too. The exception handler
of the main module displays "An external component raised an exception".
When I debug the prog, Line a displays the dialog, but when I close it,
jumps to Line b, and then to Line c (first source).
What am I doing wrong? (Accept- and CancelButton-properties of
frmSettings and the DialogResult-properties of the buttons are set).

When I copy the source from MnuExtrasSettingsClick to a timer tick event
and call it from MnuExtrasSettingsClick (Timer.Enabled = True), the
program does not crash.

What's wrong? I just don't understand it.


Thanks in advance,

Stefan

--
___________________________________www.VBTricks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_____________________________________________________
 

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