How to unload the form?

Hi
how to unload the form like Visula Basic 6 using the code unload me?
The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
Pleae help me.
Thanks!

Comments

  • : Hi
    : how to unload the form like Visula Basic 6 using the code unload me?
    : The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
    : Pleae help me.
    : Thanks!
    :
    Me. Close should only close the current form (not sure why that isn't happening in your case) However Me.Dispose will release all resources used by the form and close it also. I hope I understand what you are trying to do.
    -Larry-
  • : Hi
    : how to unload the form like Visula Basic 6 using the code unload me?
    : The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
    : Pleae help me.
    : Thanks!
    :
    I am having a similar problem:
    PLEASE HELP!
    I am having problem hiding and closing Login form:

    I have two forms: Login and Main. I have a module: Module1.

    In Sub Main I show Login form.
    When login is successful, it loads Main form.

    When the Main form is loaded, I want the login form to hide.

    On Main form I have menus: Logoff and Exit.

    When Logoff is clicked I want the Login form to show with New user string in its textbox.

    When Exit is clicked in Main then I want to close Main and Login forms.

    If I cant do this, at least I want to close the login form as soon as login is successful and reload it. Even this I was not able to do, because in Login form, when user clicks OK, the Main form is loaded and the execution go to where it says me.close in Logins OK button. It does not go there until Main form is unloaded. How can I close Login form as soon as Main is loaded?

    Code in Login form:


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    If TextBox1.Text = "Sujatha" Then
    frmNewMain.ShowDialog()
    Me.Close()
    Else
    System.Windows.Forms.MessageBox.Show("Wrong ID")
    End If
    End Sub

    Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TextBox1.Text = "Sujatha"
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    Me.Close()
    End Sub


    Code in Main form:

    Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    Me.Close()
    End Sub

    Private Sub mnuLogoff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLogoff.Click
    frmNewLogin.TextBox1.Text = "dfdjk"
    Me.Close()
    End Sub

    Code in Sub Main:

    Public frmNewLogin As New frmLogin
    Public frmNewMain As New frmMain
    Public Sub main()
    frmNewLogin.ShowDialog()
    frmNewLogin = Nothing
    frmNewMain = Nothing
    End Sub

  • : : Hi
    : : how to unload the form like Visula Basic 6 using the code unload me?
    : : The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
    : : Pleae help me.
    : : Thanks!
    : :
    : I am having a similar problem:
    : PLEASE HELP!
    : I am having problem hiding and closing Login form:
    :
    : I have two forms: Login and Main. I have a module: Module1.
    :
    : In Sub Main I show Login form.
    : When login is successful, it loads Main form.
    :
    : When the Main form is loaded, I want the login form to hide.
    :
    : On Main form I have menus: Logoff and Exit.
    :
    : When Logoff is clicked I want the Login form to show with New user string in its textbox.
    :
    : When Exit is clicked in Main then I want to close Main and Login forms.
    :
    : If I cant do this, at least I want to close the login form as soon as login is successful and reload it. Even this I was not able to do, because in Login form, when user clicks OK, the Main form is loaded and the execution go to where it says me.close in Logins OK button. It does not go there until Main form is unloaded. How can I close Login form as soon as Main is loaded?
    :
    : Code in Login form:
    :
    :
    : Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    : If TextBox1.Text = "Sujatha" Then
    : frmNewMain.ShowDialog()
    : Me.Close()
    : Else
    : System.Windows.Forms.MessageBox.Show("Wrong ID")
    : End If
    : End Sub
    :
    : Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    : 'TextBox1.Text = "Sujatha"
    : End Sub
    :
    : Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    : Me.Close()
    : End Sub
    :
    :
    : Code in Main form:
    :
    : Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    : Me.Close()
    : End Sub
    :
    : Private Sub mnuLogoff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLogoff.Click
    : frmNewLogin.TextBox1.Text = "dfdjk"
    : Me.Close()
    : End Sub
    :
    : Code in Sub Main:
    :
    : Public frmNewLogin As New frmLogin
    : Public frmNewMain As New frmMain
    : Public Sub main()
    : frmNewLogin.ShowDialog()
    : frmNewLogin = Nothing
    : frmNewMain = Nothing
    : End Sub
    :
    :
    Two things, first what form starts the project? Because if that form is closed at any time, I believe the project will end. Second, you are using the ShowDialog() method to load the new form. By using ShowDialog() the focus will become the form that was just loaded, so any thing coded after that, will not excute until the form that was called is closed.
    If your Login is the first form, I would try something like this when ok is clicked

    'check for password blah, blah blah
    Me.Hide 'Hide your login form so it is no longer visable
    frmMain.ShowDialog() 'Will transfer focus to the Main form
    txtbox1.Text = "Select different login" 'Will put this string in textbox
    Me.Show ' Will be executed when Main is closed to re-show Login

    In you Main form when Exit is clicked, use the END command to end the program. It will close everything and stop the program.
    I hope this helps and that I understood what you were trying to do. If you have any other questions please ask. lrs013400@hotmail.com
    Please note, I'm a newbie myself, so I'm learning as I go along.
  • : : : Hi
    : : : how to unload the form like Visula Basic 6 using the code unload me?
    : : : The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
    : : : Pleae help me.
    : : : Thanks!
    : : :
    : : I am having a similar problem:
    : : PLEASE HELP!
    : : I am having problem hiding and closing Login form:
    : :
    : : I have two forms: Login and Main. I have a module: Module1.
    : :
    : : In Sub Main I show Login form.
    : : When login is successful, it loads Main form.
    : :
    : : When the Main form is loaded, I want the login form to hide.
    : :
    : : On Main form I have menus: Logoff and Exit.
    : :
    : : When Logoff is clicked I want the Login form to show with New user string in its textbox.
    : :
    : : When Exit is clicked in Main then I want to close Main and Login forms.
    : :
    : : If I cant do this, at least I want to close the login form as soon as login is successful and reload it. Even this I was not able to do, because in Login form, when user clicks OK, the Main form is loaded and the execution go to where it says me.close in Logins OK button. It does not go there until Main form is unloaded. How can I close Login form as soon as Main is loaded?
    : :
    : : Code in Login form:
    : :
    : :
    : : Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    : : If TextBox1.Text = "Sujatha" Then
    : : frmNewMain.ShowDialog()
    : : Me.Close()
    : : Else
    : : System.Windows.Forms.MessageBox.Show("Wrong ID")
    : : End If
    : : End Sub
    : :
    : : Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    : : 'TextBox1.Text = "Sujatha"
    : : End Sub
    : :
    : : Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    : : Me.Close()
    : : End Sub
    : :
    : :
    : : Code in Main form:
    : :
    : : Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    : : Me.Close()
    : : End Sub
    : :
    : : Private Sub mnuLogoff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLogoff.Click
    : : frmNewLogin.TextBox1.Text = "dfdjk"
    : : Me.Close()
    : : End Sub
    : :
    : : Code in Sub Main:
    : :
    : : Public frmNewLogin As New frmLogin
    : : Public frmNewMain As New frmMain
    : : Public Sub main()
    : : frmNewLogin.ShowDialog()
    : : frmNewLogin = Nothing
    : : frmNewMain = Nothing
    : : End Sub
    : :
    : :
    : Two things, first what form starts the project? Because if that form is closed at any time, I believe the project will end. Second, you are using the ShowDialog() method to load the new form. By using ShowDialog() the focus will become the form that was just loaded, so any thing coded after that, will not excute until the form that was called is closed.
    : If your Login is the first form, I would try something like this when ok is clicked
    :
    : 'check for password blah, blah blah
    : Me.Hide 'Hide your login form so it is no longer visable
    : frmMain.ShowDialog() 'Will transfer focus to the Main form
    : txtbox1.Text = "Select different login" 'Will put this string in textbox
    : Me.Show ' Will be executed when Main is closed to re-show Login
    :
    : In you Main form when Exit is clicked, use the END command to end the program. It will close everything and stop the program.
    : I hope this helps and that I understood what you were trying to do. If you have any other questions please ask. lrs013400@hotmail.com
    : Please note, I'm a newbie myself, so I'm learning as I go along.
    :
    Thanks for your reply.
    I tried what you suggested, but I still the Login form in the taskbar.
  • : : : : Hi
    : : : : how to unload the form like Visula Basic 6 using the code unload me?
    : : : : The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
    : : : : Pleae help me.
    : : : : Thanks!
    : : : :
    : : : I am having a similar problem:
    : : : PLEASE HELP!
    : : : I am having problem hiding and closing Login form:
    : : :
    : : : I have two forms: Login and Main. I have a module: Module1.
    : : :
    : : : In Sub Main I show Login form.
    : : : When login is successful, it loads Main form.
    : : :
    : : : When the Main form is loaded, I want the login form to hide.
    : : :
    : : : On Main form I have menus: Logoff and Exit.
    : : :
    : : : When Logoff is clicked I want the Login form to show with New user string in its textbox.
    : : :
    : : : When Exit is clicked in Main then I want to close Main and Login forms.
    : : :
    : : : If I cant do this, at least I want to close the login form as soon as login is successful and reload it. Even this I was not able to do, because in Login form, when user clicks OK, the Main form is loaded and the execution go to where it says me.close in Logins OK button. It does not go there until Main form is unloaded. How can I close Login form as soon as Main is loaded?
    : : :
    : : : Code in Login form:
    : : :
    : : :
    : : : Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    : : : If TextBox1.Text = "Sujatha" Then
    : : : frmNewMain.ShowDialog()
    : : : Me.Close()
    : : : Else
    : : : System.Windows.Forms.MessageBox.Show("Wrong ID")
    : : : End If
    : : : End Sub
    : : :
    : : : Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    : : : 'TextBox1.Text = "Sujatha"
    : : : End Sub
    : : :
    : : : Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    : : : Me.Close()
    : : : End Sub
    : : :
    : : :
    : : : Code in Main form:
    : : :
    : : : Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    : : : Me.Close()
    : : : End Sub
    : : :
    : : : Private Sub mnuLogoff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLogoff.Click
    : : : frmNewLogin.TextBox1.Text = "dfdjk"
    : : : Me.Close()
    : : : End Sub
    : : :
    : : : Code in Sub Main:
    : : :
    : : : Public frmNewLogin As New frmLogin
    : : : Public frmNewMain As New frmMain
    : : : Public Sub main()
    : : : frmNewLogin.ShowDialog()
    : : : frmNewLogin = Nothing
    : : : frmNewMain = Nothing
    : : : End Sub
    : : :
    : : :
    : : Two things, first what form starts the project? Because if that form is closed at any time, I believe the project will end. Second, you are using the ShowDialog() method to load the new form. By using ShowDialog() the focus will become the form that was just loaded, so any thing coded after that, will not excute until the form that was called is closed.
    : : If your Login is the first form, I would try something like this when ok is clicked
    : :
    : : 'check for password blah, blah blah
    : : Me.Hide 'Hide your login form so it is no longer visable
    : : frmMain.ShowDialog() 'Will transfer focus to the Main form
    : : txtbox1.Text = "Select different login" 'Will put this string in textbox
    : : Me.Show ' Will be executed when Main is closed to re-show Login
    : :
    : : In you Main form when Exit is clicked, use the END command to end the program. It will close everything and stop the program.
    : : I hope this helps and that I understood what you were trying to do. If you have any other questions please ask. lrs013400@hotmail.com
    : : Please note, I'm a newbie myself, so I'm learning as I go along.
    : :
    : Thanks for your reply.
    : I tried what you suggested, but I still the Login form in the taskbar.
    :
    You can set the property of the Login form to show in taskbar = false. It's one the properties you can set.

  • : : : : : Hi
    : : : : : how to unload the form like Visula Basic 6 using the code unload me?
    : : : : : The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
    : : : : : Pleae help me.
    : : : : : Thanks!
    : : : : :
    : : : : I am having a similar problem:
    : : : : PLEASE HELP!
    : : : : I am having problem hiding and closing Login form:
    : : : :
    : : : : I have two forms: Login and Main. I have a module: Module1.
    : : : :
    : : : : In Sub Main I show Login form.
    : : : : When login is successful, it loads Main form.
    : : : :
    : : : : When the Main form is loaded, I want the login form to hide.
    : : : :
    : : : : On Main form I have menus: Logoff and Exit.
    : : : :
    : : : : When Logoff is clicked I want the Login form to show with New user string in its textbox.
    : : : :
    : : : : When Exit is clicked in Main then I want to close Main and Login forms.
    : : : :
    : : : : If I cant do this, at least I want to close the login form as soon as login is successful and reload it. Even this I was not able to do, because in Login form, when user clicks OK, the Main form is loaded and the execution go to where it says me.close in Logins OK button. It does not go there until Main form is unloaded. How can I close Login form as soon as Main is loaded?
    : : : :
    : : : : Code in Login form:
    : : : :
    : : : :
    : : : : Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    : : : : If TextBox1.Text = "Sujatha" Then
    : : : : frmNewMain.ShowDialog()
    : : : : Me.Close()
    : : : : Else
    : : : : System.Windows.Forms.MessageBox.Show("Wrong ID")
    : : : : End If
    : : : : End Sub
    : : : :
    : : : : Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    : : : : 'TextBox1.Text = "Sujatha"
    : : : : End Sub
    : : : :
    : : : : Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    : : : : Me.Close()
    : : : : End Sub
    : : : :
    : : : :
    : : : : Code in Main form:
    : : : :
    : : : : Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    : : : : Me.Close()
    : : : : End Sub
    : : : :
    : : : : Private Sub mnuLogoff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLogoff.Click
    : : : : frmNewLogin.TextBox1.Text = "dfdjk"
    : : : : Me.Close()
    : : : : End Sub
    : : : :
    : : : : Code in Sub Main:
    : : : :
    : : : : Public frmNewLogin As New frmLogin
    : : : : Public frmNewMain As New frmMain
    : : : : Public Sub main()
    : : : : frmNewLogin.ShowDialog()
    : : : : frmNewLogin = Nothing
    : : : : frmNewMain = Nothing
    : : : : End Sub
    : : : :
    : : : :
    : : : Two things, first what form starts the project? Because if that form is closed at any time, I believe the project will end. Second, you are using the ShowDialog() method to load the new form. By using ShowDialog() the focus will become the form that was just loaded, so any thing coded after that, will not excute until the form that was called is closed.
    : : : If your Login is the first form, I would try something like this when ok is clicked
    : : :
    : : : 'check for password blah, blah blah
    : : : Me.Hide 'Hide your login form so it is no longer visable
    : : : frmMain.ShowDialog() 'Will transfer focus to the Main form
    : : : txtbox1.Text = "Select different login" 'Will put this string in textbox
    : : : Me.Show ' Will be executed when Main is closed to re-show Login
    : : :
    : : : In you Main form when Exit is clicked, use the END command to end the program. It will close everything and stop the program.
    : : : I hope this helps and that I understood what you were trying to do. If you have any other questions please ask. lrs013400@hotmail.com
    : : : Please note, I'm a newbie myself, so I'm learning as I go along.
    : : :
    : : Thanks for your reply.
    : : I tried what you suggested, but I still the Login form in the taskbar.
    : :
    : You can set the property of the Login form to show in taskbar = false. It's one the properties you can set.
    :
    :
    GREAT! You solved my problem. Thanks.
  • : : : : : : Hi
    : : : : : : how to unload the form like Visula Basic 6 using the code unload me?
    : : : : : : The VB.net code me.close() will close all the forms while me.hide() cannot erase the unwanted form from the memory.
    : : : : : : Pleae help me.
    : : : : : : Thanks!
    : : : : : :
    : : : : : I am having a similar problem:
    : : : : : PLEASE HELP!
    : : : : : I am having problem hiding and closing Login form:
    : : : : :
    : : : : : I have two forms: Login and Main. I have a module: Module1.
    : : : : :
    : : : : : In Sub Main I show Login form.
    : : : : : When login is successful, it loads Main form.
    : : : : :
    : : : : : When the Main form is loaded, I want the login form to hide.
    : : : : :
    : : : : : On Main form I have menus: Logoff and Exit.
    : : : : :
    : : : : : When Logoff is clicked I want the Login form to show with New user string in its textbox.
    : : : : :
    : : : : : When Exit is clicked in Main then I want to close Main and Login forms.
    : : : : :
    : : : : : If I cant do this, at least I want to close the login form as soon as login is successful and reload it. Even this I was not able to do, because in Login form, when user clicks OK, the Main form is loaded and the execution go to where it says me.close in Logins OK button. It does not go there until Main form is unloaded. How can I close Login form as soon as Main is loaded?
    : : : : :
    : : : : : Code in Login form:
    : : : : :
    : : : : :
    : : : : : Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    : : : : : If TextBox1.Text = "Sujatha" Then
    : : : : : frmNewMain.ShowDialog()
    : : : : : Me.Close()
    : : : : : Else
    : : : : : System.Windows.Forms.MessageBox.Show("Wrong ID")
    : : : : : End If
    : : : : : End Sub
    : : : : :
    : : : : : Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    : : : : : 'TextBox1.Text = "Sujatha"
    : : : : : End Sub
    : : : : :
    : : : : : Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    : : : : : Me.Close()
    : : : : : End Sub
    : : : : :
    : : : : :
    : : : : : Code in Main form:
    : : : : :
    : : : : : Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    : : : : : Me.Close()
    : : : : : End Sub
    : : : : :
    : : : : : Private Sub mnuLogoff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuLogoff.Click
    : : : : : frmNewLogin.TextBox1.Text = "dfdjk"
    : : : : : Me.Close()
    : : : : : End Sub
    : : : : :
    : : : : : Code in Sub Main:
    : : : : :
    : : : : : Public frmNewLogin As New frmLogin
    : : : : : Public frmNewMain As New frmMain
    : : : : : Public Sub main()
    : : : : : frmNewLogin.ShowDialog()
    : : : : : frmNewLogin = Nothing
    : : : : : frmNewMain = Nothing
    : : : : : End Sub
    : : : : :
    : : : : :
    : : : : Two things, first what form starts the project? Because if that form is closed at any time, I believe the project will end. Second, you are using the ShowDialog() method to load the new form. By using ShowDialog() the focus will become the form that was just loaded, so any thing coded after that, will not excute until the form that was called is closed.
    : : : : If your Login is the first form, I would try something like this when ok is clicked
    : : : :
    : : : : 'check for password blah, blah blah
    : : : : Me.Hide 'Hide your login form so it is no longer visable
    : : : : frmMain.ShowDialog() 'Will transfer focus to the Main form
    : : : : txtbox1.Text = "Select different login" 'Will put this string in textbox
    : : : : Me.Show ' Will be executed when Main is closed to re-show Login
    : : : :
    : : : : In you Main form when Exit is clicked, use the END command to end the program. It will close everything and stop the program.
    : : : : I hope this helps and that I understood what you were trying to do. If you have any other questions please ask. lrs013400@hotmail.com
    : : : : Please note, I'm a newbie myself, so I'm learning as I go along.
    : : : :
    : : : Thanks for your reply.
    : : : I tried what you suggested, but I still the Login form in the taskbar.
    : : :
    : : You can set the property of the Login form to show in taskbar = false. It's one the properties you can set.
    : :
    : :
    : GREAT! You solved my problem. Thanks.
    :

  • Soory i forgot to erase everything first here is the simplest code you will ever need for unloading a form Note this is for a close button, it also works for menu button you just have to change the name.

    private sub cmdclose_click()
    unload me
    end sub

  • Hi desrtrat,

    Don't want to burst your balloon as you are obviously just trying to be helpful to fellow members. But your code only works in VB.Old and will not compile in VB.Net - which is the language of choice in this forum. ;-)

    You're right, though - it [b]is[/b] really handy in VB.Old.

    Ged

    : Soory i forgot to erase everything first here is the simplest code you will ever need for unloading a form Note this is for a close button, it also works for menu button you just have to change the name.
    :
    : private sub cmdclose_click()
    : unload me
    : end sub
    :

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