By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,713 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,713 IT Pros & Developers. It's quick & easy.

Modal dialogs hang up my program

P: n/a
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
__________________________________________________ ___
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi,

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

If fSettings.ShowDialog() = DialogResult.OK Then

Ken
---------------------
"VBTricks.de.vu Webmaster" <no****@thisserverdoesntexist.com> wrote in
message news:OK**************@TK2MSFTNGP12.phx.gbl...
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
__________________________________________________ ___
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.