Simple But Urgent

[b][red]This message was edited by wvbotha at 2006-5-3 11:32:28[/red][/b][hr]
Hi,
This Form is MDI Form.i wont to add simple msgbox before exit from the program, it ll ask "Are You Sure You Wont to Quit?"i did that in form disposed event as follows. but even i click "no" program exit.can somebody help me?????????? But This work in vb6.0 with the unload event.

Private Sub Main_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
Dim aa As String
aa = MsgBox("Are You Sure You Wont to Quit?",MsgBoxStyle.YesNo)
If aa = vbYes Then
End
End If
End Sub


Comments

  • Hi,

    With a bit of debugging i found this works. :-)

    [code]
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

    Dim result As String
    result = MsgBox("Are You Sure You Want to Quit?", MsgBoxStyle.YesNo)
    If result = "6" Then
    End
    Else
    Exit Sub
    End If
    End Sub
    [/code]


    Regards,

    Dr M.


  • [b][red]This message was edited by DrMarten at 2006-5-4 2:1:46[/red][/b][hr]

    Hi,

    Even if you change your routine to read>>
    [code]
    Private Sub Main_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
    Dim aa As String
    aa = MsgBox("Are You Sure You Wont to Quit?",MsgBoxStyle.YesNo)
    If aa = vbYes Then
    End
    Else
    Exit Sub
    End If
    End Sub
    [/code]

    VB.Net gets stuck in the routine below, which is part of the
    " Windows Form Designer generated code " SECTION.
    [code]
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    End Sub
    [/code]

    If you made aa a GLOBAL variable you could alter the above sub to read>>
    [code]
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    If aa=vbNo then
    Exit Sub
    End If
    End Sub
    [/code]

    You would have to
    [code]
    Dim aa As String
    [/code]

    just below the>>
    " Windows Form Designer generated code " line of course.



    Regards,

    Dr M.
    [b][blue]
    P.S. I've tried the above and VB.Net 2003 in Studio Pro still gets stuck, probably because it has no FORM object to go to i guess after disposing?[/blue][/b]

  • [b][red]This message was edited by jbassmanp at 2006-5-4 14:29:43[/red][/b][hr]

    : VB.Net gets stuck in the routine below, which is part of the
    : " Windows Form Designer generated code " SECTION.
    : [code]
    : 'Form overrides dispose to clean up the component list.
    : Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    : If disposing Then
    : If Not (components Is Nothing) Then
    : components.Dispose()
    : End If
    : End If
    : MyBase.Dispose(disposing)
    : End Sub
    : [/code]
    :
    : If you made aa a GLOBAL variable you could alter the above sub to read>>
    : [code]
    : 'Form overrides dispose to clean up the component list.
    : Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    : If disposing Then
    : If Not (components Is Nothing) Then
    : components.Dispose()
    : End If
    : End If
    : MyBase.Dispose(disposing)
    : If aa=vbNo then
    : Exit Sub
    : End If
    : End Sub
    : [/code]
    :
    : You would have to
    : [code]
    : Dim aa As String
    : [/code]
    :
    : just below the>>
    : " Windows Form Designer generated code " line of course.
    :
    :
    :
    : Regards,
    :
    : Dr M.
    : [b][blue]
    : P.S. I've tried the above and VB.Net 2003 in Studio Pro still gets stuck, probably because it has no FORM object to go to i guess after disposing?[/blue][/b]
    :
    :
    Hi
    I believe Dr M is right the disposing command has forced some reference out of memory and the only way back that I have found is with something like this.
    [code]
    Private Sub Main_Disposed(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles MyBase.Disposed
    Dim aa As String
    aa = MsgBox("Are You Sure You Wont to
    Quit?",MsgBoxStyle.YesNo)
    If aa = vbYes Then
    End
    Else
    dim f1 as new Mainform
    f1.show
    End If
    end sub
    [/code]
    this brings you back to the main form....whatever its name may be. There may be some other problems stack wise haven't test enough.

    jbassmanp





  • : Hi,
    : This Form is MDI Form.i wont to add simple msgbox before exit from the program, it ll ask "Are You Sure You Wont to Quit?"i did that in form disposed event as follows. but even i click "no" program exit.can somebody help me?????????? But This work in vb6.0 with the unload event.
    :
    : Private Sub Main_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
    : Dim aa As String
    : aa = MsgBox("Are You Sure You Wont to Quit?",MsgBoxStyle.YesNo)
    : If aa = vbYes Then
    : End
    : End If
    : End Sub
    ======================================================================

    Hi,

    If you trace the code as per my last message, the program has nothing to go back to due to DISPOSING. You would need to get the code to reload your WHOLE PROGRAM's objects. I.E. FORM, BUTTONS and all.

    By the way if it works from a button it should work from a MENU item too or any other OBJECT being clicked on "EXCEPT FOR THE RED closing X" as you are intercepting the DISPOSE method.


    Regards,

    Dr M.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories