Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

This is security for my program. When the number 2 is entered(the correct password) i want my main form (form1) to load in which it does fine but i dont want the login form (form3) to stay open if the password is correct. Could someone please tell me in detail how to use the form.close close command or something. Here is the code. Thank you

 

If TextBox1.Text = 2 Then frmform1.Show()

Thanks for any Help!!!

-Rob

Posted

Dear Rob,

You could do the following

a) either hide the loging form(Form 3) and then show it after you execute your main form(form1).

or

b) close form3 after you open form1.

 

a) if TextBox1.Text = 2 Then

me.hide()

frmform1.ShowDialog()

me.show()

end if

 

or b)

1)

form 3 will close before u use form 1

if TextBox1.Text = 2 Then

frmform1.Show()

me.close()

end if

 

or

2)

Here form 3 will be closed after u finish with form1

if TextBox1.Text = 2 Then

frmform1.ShowDialog()

me.close()

end if

 

for more questions, email me on :

mohsenfarran@yahoo.com

Cheers

  • Leaders
Posted

you should never really use End to close your application as it will stop processes abruptly.

If you want to show a certain form depending on a password being correct you can do the following...

If TextBox1.Text = 2 Then
   Dim frmform1 As New Form1() '/// assuming Form1 isn't the password Form ( ie: you start your project with a different Form )
   frmform1.Show()
End If

if you want to close all your forms there are probably a few ways about it, but here's a way i wrote a while ago ( which i have got posted on the code section of VbForums.com )...

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Private frm2 As New Form2()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
   frm2.Show()
   Me.BringToFront()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objType As Type() = Reflection.Assembly.GetExecutingAssembly.GetTypes()
Dim x As Integer, i As Integer
   Try
       For x = LBound(objType) To UBound(objType)
           If Not objType(x).Name = Me.Name Then '/// make sure you dont unload this form yet.
               i = FindWindow(vbNullString, objType(x).Name)
               If Not i = 0 Then '/// make sure the form is actually Open by checking it has a Handle.
                   PostMessage(i, CInt(&H10), vbNullString, vbNullString)
               End If
           End If
       Next
   Catch ex As Exception
       MessageBox.Show("Oops, the following error occured:" & ex.Message)
   Finally
       MyBase.Close() '/// now that all the other forms are closed , unload this one.
   End Try
End Sub

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...