Hello All
I have a issue with the remember me option.
When i use
Me.Hide()
Form2.Show()
next time when i open program it remembers the username and password
but if i use
Form2.Show()
Me.Close()
Next time when i open the program Session is = True but username and password are gone wtf??
Can someone check it out and say me how to fix it or where i make wrong .
Thank you
My Code:
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MysqlConn As MySqlConnection
Dim Command As MySqlCommand
Private WithEvents tmr As New Timer With {.Interval = 15}
Dim SAPI
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Settings.Session = True Then
txtuser.Text = My.Settings.Username
txtpass.Text = My.Settings.Password
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
End Sub
Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
ProgressBarEx1.Value += 1
If ProgressBarEx1.Value = 100 Then
tmr.Stop()
ProgressBarEx1.ShowPercentage = False
ProgressBarEx1.ShowText = True
ProgressBarEx1.Text = "Finished"
Dim conn As MySqlConnection
Dim cmd As New MySqlCommand
conn = New MySqlConnection
conn.ConnectionString = "server=localhost;port=3306;userid=root;password=password21;database=ycdata"
Dim Reader As MySqlDataReader
Try
conn.Open()
Dim query As String
query = "select ucode from users where uname= '" & txtuser.Text & "' and upassword = '" & txtpass.Text & "' "
cmd = New MySqlCommand(query, conn)
Reader = cmd.ExecuteReader
Dim count As Integer
count = 0
While Reader.Read
count = count + 1
End While
If count = 1 Then
Dim usertype = Reader.GetString("ucode")
If usertype = "1" Then
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Welcome" & txtuser.Text)
For j = 0 To 500
Next
Me.Hide()
Form2.Show()
If CheckBox1.Checked = True Then
My.Settings.Session = True
My.Settings.Username = txtuser.Text
My.Settings.Password = txtpass.Text
My.Settings.Save()
My.Settings.Reload()
ElseIf CheckBox1.Checked = False Then
My.Settings.Session = False
My.Settings.Username = String.Empty
My.Settings.Password = String.Empty
My.Settings.Reset()
My.Settings.Save()
My.Settings.Reload()
End If
conn.Close()
conn.Dispose()
ElseIf usertype = "0" Then
For j = 0 To 500
Next
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Welcome" & txtuser.Text)
Form3.Show()
Me.Close()
If CheckBox1.Checked = True Then
My.Settings.Session = True
My.Settings.Username = txtuser.Text
My.Settings.Password = txtpass.Text
My.Settings.Save()
My.Settings.Reload()
ElseIf CheckBox1.Checked = False Then
My.Settings.Session = False
My.Settings.Username = String.Empty
My.Settings.Password = String.Empty
My.Settings.Reset()
My.Settings.Save()
My.Settings.Reload()
End If
ElseIf usertype > 1 Then
MsgBox("Error: User Details #1")
End If
Else
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Please Try Again")
txtuser.Text = ""
txtpass.Text = ""
txtuser.Focus()
End If
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
txtuser.Text = ""
txtpass.Text = ""
End Try
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If txtpass.Text = "" Or txtuser.Text = "" Then
MessageBox.Show("Please Fill in Empty TextBox!", "Error")
txtuser.Focus()
Else
lblStatus.Visible = True
ProgressBarEx1.Visible = True
ProgressBarEx1.Value = 0
ProgressBarEx1.ShowPercentage = True
ProgressBarEx1.ShowText = False
tmr.Start()
End If
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
If txtpass.UseSystemPasswordChar = True Then
txtpass.UseSystemPasswordChar = False
Else
txtpass.UseSystemPasswordChar = True
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If txtuser.Text = "" And txtpass.Text = "" Then
MsgBox("Sorry its already empty")
Else
CheckBox1.Checked = False
My.Settings.Session = False
My.Settings.Username = String.Empty
My.Settings.Password = String.Empty
My.Settings.Reset()
My.Settings.Save()
txtuser.Text = ""
txtpass.Text = ""
txtuser.Focus()
End If
End Sub
Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click
Application.Exit()
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
If IsFormBeingDragged Then
Dim newLocation As Point = New Point()
newLocation.X = Me.Location.X + (e.X - MouseDownX)
newLocation.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = newLocation
newLocation = Nothing
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
End Sub
End Class
What I have tried:
I have tried options my.settings.save
my.setting.reload
my.setting.reset
none help of this, only if my form1.hide() then its working but i want to close form1 and go to form2 or form3 and next time when login to program to remember the name.