Click here to Skip to main content
15,915,172 members
Home / Discussions / C#
   

C#

 
GeneralRe: set the property of the file created to be hidden Pin
Wayne Phipps25-Feb-06 2:28
Wayne Phipps25-Feb-06 2:28 
GeneralRe: set the property of the file created to be hidden Pin
batmanAgen25-Feb-06 4:15
batmanAgen25-Feb-06 4:15 
QuestionExport C function? Pin
Dominik Reichl24-Feb-06 22:45
Dominik Reichl24-Feb-06 22:45 
AnswerRe: Export C function? Pin
CWIZO25-Feb-06 3:11
CWIZO25-Feb-06 3:11 
GeneralRe: Export C function? Pin
Dominik Reichl25-Feb-06 3:33
Dominik Reichl25-Feb-06 3:33 
GeneralRe: Export C function? Pin
User 665825-Feb-06 3:40
User 665825-Feb-06 3:40 
AnswerRe: Export C function? Pin
Eric Dahlvang25-Feb-06 4:55
Eric Dahlvang25-Feb-06 4:55 
QuestionLogin Process - Is there a better way? Pin
Wayne Phipps24-Feb-06 22:15
Wayne Phipps24-Feb-06 22:15 
I have an application where a customers may want to restrict access to specific features so I want to have some kind of user database to control access.

Now using this 'Login' is optional, the customers may not require/want to restrict access, so there is an option to 'show the login screen' (or not).

The idea I had was, if the users do not login using the login screen, there is another option which can restrict the users access because the app logs them in as an 'anonymous' user if the login is not used and privelages can be assigned to the anonymous user.

Now it appeared that as this is a windows forms app, the normal start-up form named 'MainForm' was not what I needed. I needed some kind of loop so that the login was shown (if required) and the main form was shown only if a valid user was logged in (this incudes anonymous).

I rigged up a couple of test applications and have come up with the following sample code:
private static void Start()
{
    //instanciate a new main menu object
    MainMenu mainMenu = new MainMenu();

    //instanciate a new login object
    Login login = new Login();

    //load the configuration
    Config.load();

    //check if login screen must be used
    ShowLogin = Config.LoginRequired;

    //execute the loop if not shutting down
    while ( !Shutdown )
    {
        //check if the login screen is required
        if ( ShowLogin )
        {
            //show the login
            login.ShowDialog();
        } else {
            //login user using anonymous profile
            UserName = "Anonymous";
        }

        //check if a user was logged in
        if ( !Shutdown && UserName != null )
        {
            //show the main menu
            mainMenu.ShowDialog();
        }
    }
}

[STAThread]
public static void Main(string[] args)
{
    //start the application process loop
    Application.Start();
    //start the message pump
    System.Windows.Forms.Application.Run();
}

Now, as you can see, by using Application.Run() I don't start the app by loading a form.

Its the Start method of my Application class which actually decides what should be shown.

Now what I don't like is:
1) I have to use System.Windows.Forms.Application.Exit(); in my main menu and login form if I want to exit the app.
2) Its not very Object Oriented code, it is very procedural in style.

My questions are:
Is there a better way, perhaps more Object Oriented?
Is it good practice to start and end an application in this manor?

As always, your thoughts/comments are appreciated.



Regards

Wayne Phipps
____________

Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog

QuestionVisual Studio 2005 - Slow as a dog Pin
AJ12324-Feb-06 22:06
AJ12324-Feb-06 22:06 
AnswerRe: Visual Studio 2005 - Slow as a dog Pin
Kevin McFarlane25-Feb-06 2:28
Kevin McFarlane25-Feb-06 2:28 
AnswerRe: Visual Studio 2005 - Slow as a dog Pin
redfish3425-Feb-06 3:37
redfish3425-Feb-06 3:37 
AnswerRe: Visual Studio 2005 - Slow as a dog Pin
Joe Woodbury25-Feb-06 9:02
professionalJoe Woodbury25-Feb-06 9:02 
QuestionDynamic (Runtime) Reports using Crystal Reports and DataSets Pin
AesopTurtle24-Feb-06 22:00
AesopTurtle24-Feb-06 22:00 
AnswerRe: Dynamic (Runtime) Reports using Crystal Reports and DataSets Pin
darkelv24-Feb-06 22:15
darkelv24-Feb-06 22:15 
Questionabout richtextbox Pin
cauvang24-Feb-06 18:30
cauvang24-Feb-06 18:30 
AnswerRe: about richtextbox Pin
James Gupta24-Feb-06 22:08
professionalJames Gupta24-Feb-06 22:08 
GeneralRe: about richtextbox Pin
cauvang24-Feb-06 22:30
cauvang24-Feb-06 22:30 
GeneralRe: about richtextbox Pin
James Gupta25-Feb-06 0:11
professionalJames Gupta25-Feb-06 0:11 
GeneralRe: about richtextbox Pin
cauvang25-Feb-06 14:48
cauvang25-Feb-06 14:48 
QuestionError Binding to Target Method Pin
gantww24-Feb-06 16:43
gantww24-Feb-06 16:43 
Questionedge detection Pin
haytham_mohammad24-Feb-06 16:19
haytham_mohammad24-Feb-06 16:19 
AnswerRe: edge detection Pin
mav.northwind24-Feb-06 21:01
mav.northwind24-Feb-06 21:01 
GeneralRe: edge detection Pin
AJ12324-Feb-06 22:04
AJ12324-Feb-06 22:04 
GeneralRe: edge detection Pin
haytham_mohammad25-Feb-06 8:44
haytham_mohammad25-Feb-06 8:44 
QuestionHow to read (like text to speech of Microsoft) a text in textbox? Pin
largs24-Feb-06 15:57
largs24-Feb-06 15:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.