I have an app with a log on screen. The user that logs on can have administrator access - this information need passing to the form that opens when they log on.
on the logon form i have:
string admin = "yes";
or
string admin = "no";
When the next from opens it needs to know if admin is yes or no. The new form disables functions if the log on is not an administrator.
Loading
Raja KrishnamurthyPosted Apr 13, 2011, 3:33 PM
Ex,
public static class Global
{
public static bool isAdmin {get; set;}
}
now you can set the value from your form like Global.isAdmin = true; //or false as the case maybe
and access it in other form like
if (Global.isAdmin)
//do what you need to do for admin
you can learn more about static classes and members here.
HTH
Sam HobbsPosted Apr 13, 2011, 9:10 PM
Application.Run(new FormLogon());
Then the change is likely as easy as:FormMain mf = new FormMain();
Application.Run(mf);
Application.Run(new FormLogon());
Except in FormMain you need to add a public member or property called admin. Then in the FormMain's Load event you use admin. This exact code will not do what you need to do but I don't know enough of the details of what you need to do to be able to be more accurate about the code.FormMain mf = new FormMain();
mf.admin = "yes";
Application.Run(mf);
Another possibility is to create a constructor for FormMain that has a parameter for admin but that might be too advanced for you.
All of this will be very easy to understand when you become familiar with the basics of the C# language.
Richard BrennanPosted Apr 13, 2011, 8:20 PM
But I first tried to add the static class to a new project type, class library - and it did not work. Do u know why?