Zz vc # winform-based system logon program solution under. net

Source: Internet
Author: User
How to solve the winform-based system logon program in VC #. net

Background(Nonsense and feelings ):
It has been a long time for me to get started with. net, but I have never had time to study it seriously.
I have been learning C #, ASP. NET, and ADO. Net for more than a week. I learned it with a project! :) First, I visited multiple local bookstores and bought a pile of books, including ADO. Net program design.
<Construct a web solution -- apply ASP. NET and ADO. Net> <Visual C #. NET technology insider> <. Net frameword advanced programming> 〉. These books have helped me a lot. I have almost finished reading the first two books. The following two documents are for reference only. Of course, the biggest help to me is csdn's netizens.
Summary:
VC # A winform-based system login program solution under. net!
Detailed Problem description:
Use VC #. net
Create a winform-based project that contains a main window and a logon window. The main window contains several menu items, and the main () function is in the main window. The logon window contains the user name input box and password
Code input box, user type selection box, OK button. When loading the main window, the logon window is displayed. Enter the user name and password, select the user type, and click OK. User verification
After authentication, the logon window is automatically closed. At this time, the specific menu of the main window becomes available, and some menus become unavailable, that is, the enabled attribute of the menu is changed. The main window changes to the current active window. If the user
If the logon window is closed without verification, all menus are disabled.

Netizen solution:
I,
1. Create a login form, place the main () method in the form, and make it the main form;
2. Add an int type parameter logintype to the constructor of your original main window (you want to modify the menu attribute;
3. In the "OK" button event of the login form, set an int value based on the user identity type, for example, the Administrator is 0, and the general user is 1. Then generate your main form with menu, and pass the integer to its constructor;
4. In the form_load event of your main form with a menu, set the available and unavailable menu items based on the logintype value.
Hope to help you

My understanding of this solution:

Very
Thank you for your suggestions! First of all, this method does not meet my needs. I want to display a user logon interface when loading the main window (that is, the one with the menu. The logon field is disabled only when the logon is successful.
And then display a specific menu in the Main Window Based on the user type. If you close this logon interface, disable all menus. I used your method first, but after the main form is displayed, the login form does not
When you close the logon window, you must close the main window because the main function main () is in the logon window. Although you can hide the logon window, I did not try it! :)

II,
The following method can be used as a result. After the user starts the program, the main window appears first, but all the menus are forbidden. Then the login window appears, and the user must log on to the system. Otherwise, the system will exit. after a user logs in, different menus are displayed based on different users.
1. design the main form frmmain as the startup form, that is, this form contains main ().
Private string strlogin = "";

Private void frmmain_load ()
{
// Disable all menus
}
Private void frmmain_activate ()
{
If (this. strlogin! = "") Return;

Frmlogin myfrmlogin = new frmlogin ();
 
If (myfrmlogin. myshowdialog (ref strlogin ))
{
This. Close ();
Return;
}

// Determine the login user type and display the menus.
}
2. design the login window frmlogin.
Public bool myfrmshowdialog (string ref strplogin)
{
This. showdialog ();
// Return to the login user.
If (usercancel)
Return false; // if the user cancels, false is returned.
Strplogin = userinfo;
Return true;
}

My understanding of this solution:
Your suggestion is very suitable for my needs, but I don't know much about the private void frmmain_activate () event, so it cannot be solved! I checked wincv and found the activate event, but I don't know how to use it! What is it? What kind of books can I refer?

My summary of the netizen solution:
In view of the two practices, I have come up with a principle: Passing parameters to save user type information! :)

My solutions:

I designed my login program in this way. Please visit and give me some comments!
1. Load the function in the main window.
Private void form_main_load (Object sender, system. eventargs E)
{
Form_login FRM = new form_login (); // create a logon window
FRM. showdialog (); // This logon window is displayed.
If (FRM. returnusertype () = 1) // return the User Type
{
// Add and modify the menu attribute code here!

}
Else if (FRM. returnusertype () = 2)
{
// Add and modify the menu attribute code here!
}
Else if (FRM. returnusertype () = 3)
{
// Add and modify the menu attribute code here!
}
Else
{
// Frm. Close ();
}
}
2. In the logon window, add a user type variable for the logon window class,
Private int usertype;

3. In the logon window, add a public function for the logon window class to return the user type information!
Public int returnusertype ()
{
Return this. usertype;
}
4. In the confirm button Event code in the login window, save your user type information!
Private void button#click (Object sender, system. eventargs E)
{
// Some login databases, verification process
This. usertype = 1;
// This. Close ();
//.......
This. usertype = 2;
// This. Close ();
//...........
}

My summary:
Although the problem has been solved, I found that it is a problem to close the logon window. Solve the problem in button#click or in form_main_load!

The first time I wrote something, it was not very well described! I hope this will help beginners or those who are in need of this knowledge!

Finally, I would like to express my special thanks to demonhunter and Souther OF THE csdn forum)

See: http://expert.csdn.net/Expert/topic/1681/1681684.xml? Temp =. 1134607.

Technical Exchange: hgf686@sina.com

All rights reserved, which can be widely reproduced !~~

If you have any suggestions, please send me an email! Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.