Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey I have created a HWID Program to test out my program how it works. I have created 2 forms. The form1 has button1 as named "Connect" and button2 as named "My HWID". There's also a textbox1 called "txtHWID" (visible: false, readOnly: true). form2 has only one textbox called laso "txtHWID" (visible: false, readOnly: true) and when I click the button of form1 "My HWID" it opens up the form2 and shows my HWID. then one I copy and paste it to my hosting to get access then I click button1 as named "Connect" and appears "Login Successful!"

Now what I want is when button1 as named "Connect" to show "Login Successful!" and then when OK is pressed to close form1 and form2 and only display form3 as a new window. After form3 is closed then all program must be closed. Any idea? Thanks for your time!

What I have tried:

Form1:
Imports System.IO
Imports System.Management

Public Class Form1
    Private cpuInfo As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtHWID.Text = GetHWID()
        Me.AcceptButton = btnConnect
    End Sub
    Function GetHWID()
        Dim mc As New ManagementClass("win32_processor")
        Dim moc As ManagementObjectCollection = mc.GetInstances
        For Each mo As ManagementObject In moc
            If cpuInfo = "" Then
                cpuInfo = mo.Properties("processorID").Value.ToString
                Exit For
            End If
        Next
        Return cpuInfo
    End Function

    Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
        Dim Request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("...html")
        Dim Response As System.Net.HttpWebResponse = Request.GetResponse()
        Dim SR As System.IO.StreamReader = New System.IO.StreamReader(Response.GetResponseStream)
        Dim HWIDAdded As String = SR.ReadToEnd
        Dim ThisHWID As String = GetHWID()
        If HWIDAdded.Contains(ThisHWID) Then
            'CODE FOR SUCCESFUL LOGIN'
            MsgBox("Login Sucessful!", MsgBoxStyle.Information)
        Else
            'CODE FOR FAILURE LOGIN'
            Me.Close()
        End If
    End Sub

    Private Sub btnHWID_Click(sender As Object, e As EventArgs) Handles btnHWID.Click
        Form2.Show()
    End Sub
End Class


Form2:
Imports System.IO
Imports System.Management

Public Class Form2

    Dim cpuInfo As String

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtHWID.Text = GetHWID()
    End Sub

    Function GetHWID()
        Dim mc As New ManagementClass("win32_processor")
        Dim moc As ManagementObjectCollection = mc.GetInstances
        For Each mo As ManagementObject In moc
            If cpuInfo = "" Then
                cpuInfo = mo.Properties("processorID").Value.ToString
                Exit For
            End If
        Next
        Return cpuInfo
    End Function
End Class
Posted
Updated 10-Aug-19 2:04am
v2

1 solution

You can't close Form1 - if you do, the Application will terminate because Form1 is normally the form that is opened when you app starts - and closing that triggers the app to close, which will close all forms.

Instead, create your new form instance, and add a handler for it's FormClosed event to Form1.
Then call Hide on Form1 to get it out of the display, and use ShowDialog to display the new form.
In the handler, Close the main form and you are done.
 
Share this answer
 
Comments
IDKaName 10-Aug-19 8:14am    
Thanks. Is it like that?

Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
Dim messageBoxCS As System.Text.StringBuilder = New System.Text.StringBuilder()
messageBoxCS.AppendFormat("{0} = {1}", "CloseReason", e.CloseReason)
messageBoxCS.AppendLine()
MessageBox.Show(messageBoxCS.ToString(), "FormClosed Event")
End Sub
OriginalGriff 10-Aug-19 8:20am    
No, that's the Form1 FormClosed event - you need to handle the event for the new form instance, not for Form1.
Your code will only get the event just before you app closes!
So add it when you use the New keyword to create a new instance of the second (or third) form.
BobbyStrain 10-Aug-19 10:23am    
Such operations become simple if you use C# and Selenium.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900