Z. Jiménez Z. Jiménez - 6 months ago 20
Vb.net Question

result of a modal form in vb.net

I create a form 'frmX' and i call it as a modal form :

res = frmX.ShowDialog()


This form has 3 buttons, Abort(3), Retry(4) and Ignore(5), but when the form opens, all the buttons on the first click return 2.

I don't know why this occurs--all of the buttons has their property DialogResult right.

*Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
btnIgnorar.DialogResult = DialogResult.Ignore
End Sub
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
btnAbortar.DialogResult = DialogResult.Abort
End Sub
Private Sub btnReintentar_Click(sender As Object, e As EventArgs) Handles btnReintentar.Click
btnReintentar.DialogResult = DialogResult.Retry
End Sub*


Can someone help me?

Answer

The error comes from the fact that you set the DialogResult of the buttons. You must set the DialogResult of the form !

Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
    Me.DialogResult = DialogResult.Ignore
End Sub
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
    Me.DialogResult = DialogResult.Abort
End Sub
Private Sub btnReintentar_Click(sender As Object, e As EventArgs) Handles btnReintentar.Click
    Me.DialogResult = DialogResult.Retry
End Sub