0

I inherited this vb.net code and am a newbie vb.net programmer with old programming skills.

This problem exists in many places after calling a dialog box. After processing the dialog, if the enter key is pressed on the dialog instead of clicking OK, the enter key logic is then processed on the main form. This is undesirable and i need to just display the form.

It looks like "e.handled = True" may be the way to clear the key results, but it produces the "handled is not a member of Eventargs" error.

Can you please recommend the best way to handle this situation?

Thank You,

Brian

Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click

    Try
        'Get the menu off of the screen cleanly
        Application.DoEvents()

        dlgAbout.ShowDialog()
        **e.handled = True**

    Catch ex As Exception
        Call modErrorHandler.ErrorProcedure(ex.GetType.Name, Me.Name, ex.Message, ExceptionClassName(ex), ExceptionMethodName(ex), ExceptionLineNumber(ex))
    End Try

End Sub
Brian Miller
  • 11
  • 1
  • 3
  • The main form is not going to know anything about a keypress in a Dialog. Dialogs can return a DialogResult depending on which button is pressed (enter and esc are just shortcuts to those buttons/result). Capture the result and act on *that*. There simply isnt a `Handled` member of `EventArgs` as the error is telling you. – Ňɏssa Pøngjǣrdenlarp Jul 25 '16 at 16:50
  • You could use a flag to indicate that your "enter key logic" should not do anything. By the way, [How to use DoEvents() without being “evil”?](http://stackoverflow.com/a/11352575/1115360) tells of some problems with that. Maybe setting the [Menu.DisappearAfter Property](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.disappearafter(v=vs.110).aspx) would be an acceptable substitute. – Andrew Morton Jul 25 '16 at 16:51
  • 1
    @AndrewMorton : `Menu.DisappearAfter` is for when you use for example ASP.NET. This seems to be WinForms. -- Also, Brian, using the `Call` keyword in this case is superfluous. – Visual Vincent Jul 25 '16 at 22:37
  • Thank you for the input. As Plutonix mentioned, it looks like I will have to handle the action in the dialog boxes before it returns control to the main form. Yes, it is WinForms, Andrew. – Brian Miller Jul 26 '16 at 23:20

0 Answers0