Help: form focus

hi,

i have a method to close my form, but it simply send a message box to ask if i want to save the changes or not or to cancel closing the form.

the problem is when i cancel the form closing my form go back behind every running program on the desktop

here its my method tell me what is wrong on it

Private Sub Main_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Dim result As DialogResult

result = MessageBox.Show("do you want to save the changes before you close ", _

"Save Changes", MessageBoxButtons.YesNoCancel, _

MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, _

MessageBoxOptions.DefaultDesktopOnly, False)

Select Case result

Case Windows.Forms.DialogResult.OK

'todo: save the changes in the dataset then close this form

Case Windows.Forms.DialogResult.No

'todo: don't save changes and close the form

Case Windows.Forms.DialogResult.Cancel

'skip this method

e.Cancel = True

Me.Focus()

End Select

End Sub

i don't know whats wrong on it

thx bye




Answer this question

Help: form focus

  • Dave Westhead

    hi,

    Thx Mr.David it worked perfectly

    best regards



  • Marc.

    The cause of this is the MessageBoxOptions.DefaultDesktopOnly option. This option is really only for use when creating Windows Services.

    Remove the option and it should work fine.



  • Help: form focus