i need some help in VB. I just started learning vb today.
so I have an MDIParent form, which contain login, logout(disabled) and other disabled strip menu.
so when i click the login, the login form is appeared as MDI child window.
the question is, when i successfully logged in i want to make the login Strip Menu disabled, enabling the logout Strip Menu and the other strip menu. I have tried to make it. Here's my code now :
Imports MySql.Data.MySqlClient
Public Class LoginForm
Dim mdiP As New MDIParent
Dim myconn As New MySqlConnection("Server=localhost; User Id=root; Password=; Database=apotek_db")
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "" Or PasswordTextBox.Text = "" Then
MsgBox("Please insert username and password")
End If
Dim username As String = UsernameTextBox.Text
Dim password As String = PasswordTextBox.Text
Dim myAdapter As New MySqlDataAdapter("select * from admin where USERNAME = '" & username & "' and PASSWORD = '" & password & "'", myconn)
Dim myDataTable As New DataTable
myAdapter.Fill(myDataTable)
If myDataTable.Rows.Count < 1 Then
PasswordTextBox.Clear()
UsernameTextBox.Clear()
MsgBox("Invalid username or password")
Else
MsgBox(username & " Successfully logged in")
mdiP.logOutMenu.Enabled = True
mdiP.logInMenu.Enabled = False
mdiP.TransaksiPenjualanToolStripMenuItem.Enabled = True
mdiP.DataObatToolStripMenuItem.Enabled = True
Me.Close()
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
mdiP.Show()
Me.Close()
End Sub
End Class
But the code above doesn't disabling or enabling anything in the MDI parent. it just showing message box than i successfully logged in, and close the login form. thats it.
so anyone have any solution for me?
Thanks in advance,
Rezz.
Dim mdiP As New MDIParent
: You aren't referencing the existing MDI parent when you do that. The LoginForm should have a property called MDIParent — use that and cast it to your MDIParent form. – LarsTech Dec 3 '14 at 13:59