VB using me.close before opening new form

Hi Guys i'm new to Visual Basic Coding, and i can't seem to get where's my mistake on my coding, i'm trying to create a button that opens a new form while closing the current form.

i have two forms, form 1 is MainForm, form 2 is SearchForm

Whenever i use this code:

Private Sub SearchMButton_Click(sender As Object, e As EventArgs) Handles SearchMButton.Click    
        MainForm.Close()
        SearchForm.Show()
    End Sub
End Class

it will generate an error and says i need to replace MainForm.Close() into Me.Close() When i Use this

Private Sub SearchMButton_Click(sender As Object, e As EventArgs) Handles SearchMButton.Click    
        Me.Close()
        SearchForm.Show()    
    End Sub
End Class

It closes both Forms and it doesn't leave any Form Open. Kindly direct me to the proper path, thanks in advance.

Answers


You need to Hide the form rather than closing it. Since it's your main form, when it closes, the application exits.


Standard UI guidelines are to leave the main form open, and open search form on top of that. If you need to block the main form, while search criteria are selected, use .ShowDialog, instead of just .Show.

.NET WinForms programming pattern kind of implies that you never close your main form. If you deviate from this approach, you are guaranteed to encounter all sorts of layout and display issues. So please don't. You can .Hide the main form, if it needs to go to system tray or run in background.


Need Your Help

Wrong JPEG library - ruby on rails- OS X

ruby macos osx-snow-leopard jpeg

I keep getting this error any time i call any page that has a call that uses RMagick, but i can't figure out what library i'm missing, or what i need to install to get rid of this error. Does anyon...

Calculating gluLookAt, glOrtho and glFrustum

c++ opengl math 3d

I am working on an assignment to draw wire frame GLUT standard objects. This seems simple but we are told we cannot use gluAtLook(), glOrtho(), glFrustrum but we must use glTranslate(), glScale() and