I am attempting to create a License Registration addition to my program. This accesses my MySQL database, then validates the users license. This program is working so far, it can access the database and validate the license, but in an effort to make it so that the user does not have to input the license key every time, it saves the license key to a text file where in the Form_Load event, the program reads the key from there, and validates it, moving on to the next form, but as from my research, Me.Hide() doesn't work in the form_load event, where I am attempting to run it from. I have tried, and been successful with, changing the opacity to 0 or setting the form to a location way off screen, but is just not feasible, as the form is still there, just not displayed. Is there any workaround that will allow Me.Hide() in the Form_Load event? Thank you for any assistance you may provide me!
Here is my code if needed:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim file As System.IO.StreamWriter
If (Not System.IO.Directory.Exists("C:\Program Files\LicenseRegistration")) Then
System.IO.Directory.CreateDirectory("C:\Program Files\LicenseRegistration")
End If
file = My.Computer.FileSystem.OpenTextFileWriter("C:\Program Files\LicenseRegistration\key.txt", True)
file.Close()
Dim txtreader As New System.IO.StreamReader("C:\Program Files\LicenseRegistration\key.txt")
Dim Key As String
Key = txtreader.ReadLine()
txtreader.Close()
If Key = "" Then
GoTo FirstTime
End If
Dim READER As MySqlDataReader
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString =
'MySQL Login Info Cut
"server=;userid=;password=;database="
Try
MysqlConn.Open()
Dim Query As String
Query = "select * from sql373296.LicenseKeys where License_Key='" & Key & "' "
COMMAND = New MySqlCommand(Query, MysqlConn)
READER = COMMAND.ExecuteReader
Dim count As Integer
count = 0
While READER.Read
count = count + 1
End While
If count = 1 Then
Me.Hide()
Form2.Show()
Else
MsgBox("Your license has been banned!")
End If
MysqlConn.Close()
Catch ex As MySqlException
MsgBox(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub