I am using windows forms application using C#. I have created a dialog box that requests the user for login details such as a username and password. using If-else statement, If login details match, a message box stating “success” appears and the dialog box closes automatically. this is fine. but, if I enter wrong login details, I make a message box appear in the else statement, stating that “wrong details entered”. But, then when I close that message box, the dialog box disappears. I do not want this to happen. I want the dialog box to remain in view for the user to enter correct details again. is there some lines of code that I should enter to avoid closing of the dialog box?
Share
I would suggest you to create a new form and then show it as dialog:
1) Create new form
2) Set MinimizeButton of Form to false
3) Set MaximizeButton of Form to false
4) Add components: 1x textfield, 2x button (ok button and cancel button)
5) Set DialogResult of Ok Button to: OK
6) Set DialogResult of Cancel Button to: Cancel
7) Add a public method: public string GetText() { return textbox.text };
8) Set password char for textbox
In your main form:
If you want to display the Dialog in a loop, replace “if (dialogForm.ShowDialog() … ” with “while …”
Attention: Code untestet
Attention 2: Please make sure that your validation logic is safe. Experienced users can decompile your application to get the validation logic
Hope that helps? Kind regards