how to close all forms? - vb.net

log.vb
Public Class log
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "bassam" And TextBox2.Text = "bassam" Then
Me.Hide()
msgbox1.Show()
Else
Me.Dispose()
End If
End Sub
End Class
msbox1.vb
Public Class msgbox1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
In the form msgbox1, I want to close the form log when i press Button1, but it just closes the msgbox1. How can I close all the forms?

If you want to close the whole application just call Application.Exit().

Related

How do I get the parent form from a child form in VB.net?

I have a VB form which may be called by a number of forms. Upon exiting this child form, I want to restore the calling form but I cannot seem to figure out how to determine which form called it. Any help would be greatly appreciated.
You can create a tagging for parent forms (maybe a global array) which you will update the value every time you open a child form. You just have to remember which form is which on the tagging you will make.
Maybe you can try this-
Module with form tagging:
Module Module1
Public parentForms(2) As String
'parentForms(0) - parent form of Form 1
'parentForms(1) - parent form of Form 2
'parentForms(2) - parent form of Form 3
Public Sub openParentForm(ByVal ParentTag As String)
If ParentTag {use the notequal operator} "" Then
Select Case ParentTag
Case Form1.Tag
Form1.Show()
Case Form2.Tag
Form2.Show()
Case Form3.Tag
Form3.Show()
End Select
End If
End Sub
End Module
Form1:
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Tag = "Form1"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
parentForms(1) = Me.Tag
Form2.Show()
'Dont use .Close as the Parent Form will be disposed and the whole application will exit
Me.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
parentForms(2) = Me.Tag
Form3.Show()
Me.Visible = False
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call openParentForm(parentForms(0))
End Sub
End Class
Form2
Public Class Form2
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Tag = "Form2"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
parentForms(0) = Me.Tag
Form1.Show()
Me.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
parentForms(2) = Me.Tag
Form3.Show()
Me.Visible = False
End Sub
Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call openParentForm(parentForms(1))
End Sub
End Class
Form3
Public Class Form3
Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Tag = "Form3"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
parentForms(0) = Me.Tag
Form1.Show()
Me.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
parentForms(1) = Me.Tag
Form2.Show()
Me.Visible = False
End Sub
Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call openParentForm(parentForms(2))
End Sub
End Class

how to make a vb program register form

How do i make a vb program register form? like you can in steam, google, Xbox live? Register on one computer and login from another Computer? For Free? Is i could like in drop box etc? I am making a game launcher program and i want to have theme sync there stuff. I Googled it no help! The only way i know how to is a offline account. It is annoying me. I am not that good in vb.net programming. Thanks!
here is my code
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Settings.sli Then
Main.show()
End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
My.Settings.sli = 1
Else
My.Settings.sli = 0
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Settings.user = TextBox3.Text
My.Settings.pass = TextBox4.Text
My.Settings.Save()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Settings.user = TextBox1.Text And TextBox2.Text = My.Settings.pass Then
Main.Show()
Else
MsgBox("Username Or Password Wrong! Try Again!")
End If
End Sub
End Class
Thanks!

Me.Settings isn't a part of form1

me.settings isn't a part of form1
I have multiple forms, but my startup is my applications form not the login.
But here's my code for my login
Public Class Login
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = My.Settings.Username And TextBox2.Text = My.Settings.Password Then
MsgBox("Works!")
me.settings.Loggedin = true
Else
MsgBox("Missing Username or Password", MsgBoxStyle.Information, "Error")
End If
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
CreateAccount.Show()
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
I don't understand what the problem is.
The error message is informing you that the form called form1 does not have a property called Settings.
I believe you meant to say
My.Settings.Loggedin = true
instead of
me.settings.Loggedin = true
So you want the LOGIN FORM to be loaded first... then if the username and password are matching, then the APPLICATION FORM will be loaded?
If so, then you have to go to the project's properties and change the STARTUP FORM from your APPLICATION FORM's name into the LOGIN FORM's name.

Show Form2 7seconds delayed after Form1 close

I have two forms in my application, form2 is shown on clicking a button in the form1. but i need a delay of 7 seconds between form1's close and form2's show for that i wrote the following code:
Public Class Form1
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
i = 0
Me.Close()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
i += 1
If i = 7 Then
Form1.Show()
End If
End Sub
End Class
But it does not give me the result. form2 not shown at all. what was the mistake i had made in the code? can anyone help me?
Thanks in advance.
When there's no active form left in a Windows Forms application, the application will quit. Therefore, you might want to hide the main form instead of closing it:
Me.Hide()
i think no need of unnecessary declaration for time delay because you can simply set it on your timer control itself
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 7000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Form2.Show()
Me.Close()
End Sub
End Class
or
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 7000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Close()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Form2.Show()
End Sub

Error on form click object reference not set to an instance of an object

When I click form1 button 1 to show form2 but it show The error is:
Object reference not set to an instance of an object.
Form1:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2. Show()
Me.Hide()
End Sub
End Class
I suggest declaring it outside of the method, this way you can access it from other methods:
Private _Form2 as new Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me._Form2.Show()
Me.Hide()
End Sub
Try this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newform as New Form2
newform.Show()
Me.Hide()
End Sub
You can have more than one of the same form open, so you need to create an 'instance' of the form, before you tell it to show that instance.