Login Class Problems!!!
I decided to make a simple to use stand alone dll that would expose one function - AllowAccess(Title, NoAttemps, etc) as boolean. This would be called at the main programs Load event, if it returned False the program would close, if true it would keep going.
Basically the dll has a class full of controls that i have yet to add, and a form class (frmLoginGUI). This is already dimentioned, but not initialised when the function is called. I want the function to run a form, allow the user to exit, or have a set number of goes at the password. i also want the form to be a dialog form!
Basically, i can't show the form and ask for x dialog results as the result is repeated and it just closes, but i don't want to call the show dialog method with each loop, as it flashes - tacky! Any ideas?
PublicFunction AllowAccess(ByVal TitleAsString,ByVal AttemptsAllowedAsInteger)AsBooleanLoadUsers() ' gets the list of user info from a text/dat filefrmLogin =New frmLoginGUI 'instatializes the frmLoginIf frmLogin.ShowDialog() = Windows.Forms.DialogResult.OKThenIf CorrectInput(strUserName, strPassword) =TrueThenfrmLogin.Close()ReturnTrueElseintAttempts += 1EndIfElsefrmLogin.Close()ReturnFalseEndIfLoopWhile intAttempts < AttemptsAllowedfrmLogin.Close()ReturnFalseEndFunctionIf you can think of a better way to do it, let me know!
How do you mean? If i make the form show itself, and add a load of code in it to control the OK and cancel buttons, won't it get ignored as my AllowAccess function carries on, reuturns the default value and closes the program?
Some pseudo code:
Public Sub Main(Args() as string)
Dim Login as new frmLogin(WhatEverArgsYouNeed)
Login.ShowDialog()
if Login.DialogResult = OK then
Dim Main as new frmMain()
Application.Run(Main)
Else
'Whatever here
End
End Sub
Form Code:
Dim Tries as integer =0
Private Sub OK_Click(...)...
if UsernameOK and PasswordOK then
me.DialogResult = OK
else
Tries += 1
if Tries > MaxTries then
me.dialogReqult = Cancel
End If
End If
End Sub
Private Sub Cancel_Click(...)...
me.DialogResult = Cancel
End
I think i get ya point. basically, rather than hooking the dialog result up the buttons, and thereby closing the form automatically, etc, you set the result manually! This gives control and the chance to check the No.Attempts, etc!
Cheers, i'll have a go!
>> rather than hooking the dialog result up the buttons, and thereby closing the form automatically, etc, you set the result manually!
Yup! The Cancel could be hooked up, but not the OK.