Click here to Skip to main content
13,829,868 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


75 bookmarked
Posted 2 Sep 2010
Licenced CPOL

Splash and Login Forms (Problems and Solutions)

, 8 Sep 2010
Rate this:
Please Sign up or sign in to vote.
The more perfect description of the creation the Splash and the Login forms with full source code


"An investment in knowledge always pays the best interest."
Benjamin Franklin


In this article, I would like to discuss problems the Splash \ Login Forms creating. I often stumble on the questions of the novice programmers about the Splash \ Login Forms on the forums. In my opinion, the answers on these questions often don't give a comprehensive information. So I decided to write the article. It fully describes these problems and solutions.

At first, I would like to discuss a question - What causes these problems to arise? In my opinion it is connected with an insufficient information or a fuzzy concept about the Windows architecture and Windows processes when we start executing program in the Windows systems. Here's the main problem. So let's resolve it. I am not going to retell a big good books about Windows, there is no point. I only want to let you have the opportunity to know about the creation of the instance program in Windows. That will give you an understanding of how to create the Splash \ Login Forms.

What is a Process?

First, we'll discuss a definition of "process in Windows". The Process - it is a copy of the executable program, and it consists of two components:

  1. An object of the kernel, through which the operating system manages the process. It keeps the static information about the process.
  2. An address space that contains executable code and data of the process.

The process itself does nothing, i.e., it is inert. To make it do something, it should have at least one thread. The thread is responsible for the execution of code in the address space of the process. Therefore, when the process is starting, the operating system automatically creates the main thread, which in turn can generate other threads. In addition, if we want our application to respond to the mouse moving, the button clicking, and so on, we have to create a message loop in the thread. So we have some structure: process - thread - a message loop. If we want to close the program, we need to close the main message loop. It happens when you close the main form or doing method Application.Exit(), as well as the method ExitThread() in the main thread.

How Do I Do It?

All discussed above, Visual Studio creates automatically, when we choose to create a project template with Windows Forms Application. Armed with this knowledge, take a look at the code, which we all certainly have repeatedly seen:

static void Main()
    Application.Run(new Form1());

When you call a method Application.Run (new Form1 ()), we create a new thread that creates a message loop, and an object of class Form and shows it. Let us carefully consider this method. This method is overloaded, and may have the following options:

  1. Run()
  2. Run(ApplicationContext)
  3. Run(Form)

(For additional information, see this link.)

We are not interested in the first overloaded method in the context of this article, unless, of course, you decide to create something in the unsafe code, the third method we have already discussed. But the second is what we will be particularly interesting in. This creates the object class ApplicationContext, which is responsible for creating the thread and the standard cycle of message. Now everything is pretty simple - we must create a descendant class LoginTestContext of class ApplicationContext, which we will create a logic with application forms:

public class LoginTestContext: ApplicationContext
    // here we can declare the all forms application and manage it directly
    //(show, close, set as MainForm and so on) 
    private frmLogIn fLogin;
    private frmMain fMain;

    public LoginTestContext()


(For additional information, see this link.)

And our entry point into the application will look as follows:

static void Main()

     //Run the application with our context. It is splash, log and main forms
     Application.Run(new LoginTestContext());    

Creating the Splash Form

That's it! The Splash form is displayed when we need it and at the time that we need. Here, in place of slumber thread, you can do something really necessary, such as loading any resources, while showing progress bar or some other kind of information.

private static void CreateSplashForm()
     Form fSplash = new Form();
     fSplash.BackgroundImage = System.Drawing.Image.FromFile(@"backg.bmp");

     fSplash.BackgroundImageLayout = ImageLayout.Center;
     fSplash.FormBorderStyle = FormBorderStyle.None;
     fSplash.StartPosition = FormStartPosition.CenterScreen;
     fSplash.TopMost = true;
     //it sets transparency for the background of image
     fSplash.TransparencyKey = System.Drawing.Color.White;
     //set the splash form size and we are sure the image fit to the form
     fSplash.Width = (int)fSplash.BackgroundImage.PhysicalDimension.Width;
     fSplash.Height = (int)fSplash.BackgroundImage.PhysicalDimension.Height;


Creating the Login Form

Now we'll discuss the problem of the Login form establishing. The Login form follows after the Splash form. The Login form in any case should be closed. When it is closing itself, we must determine whether the login is made in the application:

private void CreateLoginForm()
    fLogin = new frmLogIn();
    fLogin.Closed += new EventHandler(fLogin_Closed);
    fLogin.TopMost = true;
void fLogin_Closed( object sender, EventArgs e )
    if (LWork.LoginWork.Login)
        fMain = new frmMain();
        this.MainForm = fMain; //set the main message loop application in this form

The registration process is implemented in a static class LoginWork.

public static void DoLogin( string NikName, string Password )
    if (IsExistNikName(NikName))
        if (_user.Password == HashString(Password))
          _Logged = true;
        _Logged = false;

The search function of the user name in the list IsExistNikName (string name) is implemented using lambda expression UserData => UserData.Nikname == NikName. In this case, the explanation the entity lambda expressions is too simple. For more information about the lambda expression, see this link.

private static bool IsExistNikName( string NikName )
    if (_UserDataList.Count == 0)
        return false;
        //here I use a lambda expression for the searching the nikname 
        //in the user data list
        _user = _UserDataList.FirstOrDefault(UserData => UserData.Nikname == NikName);

        if (String.IsNullOrEmpty(_user.Nikname))
          return false;

    return true;

For security, the user's password is hashed using the function:

public static string HashString( string s )
     //encode string to the array of bytes
     byte[] data = Encoding.Default.GetBytes(s);

     MD5 md5 = new MD5CryptoServiceProvider();
     byte[] result = md5.ComputeHash(data);
     //do hexadecimal-formatted string
     StringBuilder sb = new StringBuilder();
     foreach (byte item in result)

     return sb.ToString();

The processes of saving, load the data registered users are implemented using XML Serialization and UserData structure. The data is stored locally in the XML file:

public struct UserData
    private string _Name;

    public string Name
      get { return _Name; }
      set { _Name = value; }

    private string _Nikname;

    public string Nikname
      get { return _Nikname; }
      set { _Nikname = value; }

    private string _Password;

    public string Password
      get { return _Password; }
      set { _Password = value; }


That is all I wanted to tell you on this topic. I hope I succeeded in revealing the topic of this article fully. The implementation of the classes registration form and Login form, I think, will not cause any difficulty in understanding, but if you have any questions please write, I'll answer everyone.

Good coding!


  • Initial release: 31 August, 2010
  • Changed the code version: 3 September, 2010


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vladimir Knyazkov
Software Developer (Senior)
Ukraine Ukraine
My name is Vladimir Knyazkov. I am MCP (ID: 8647484, Transcript ID (995538)). I am from Ukraine (Kiev).

You may also be interested in...


Comments and Discussions

QuestionThanks Pin
Phan Duc Thien25-Dec-14 15:12
memberPhan Duc Thien25-Dec-14 15:12 
QuestionSplash and Login Forms (Problems and Solutions) Pin
gogaa8-Jan-14 19:09
membergogaa8-Jan-14 19:09 
GeneralMy vote of 5 Pin
gogaa8-Jan-14 19:07
membergogaa8-Jan-14 19:07 
GeneralEasy to remove protection Pin
che@free.fr2-Nov-13 6:30
memberche@free.fr2-Nov-13 6:30 
GeneralRe: Easy to remove protection Pin
Vladimir Knyazkov18-Dec-13 23:09
professionalVladimir Knyazkov18-Dec-13 23:09 
SuggestionVery good article Pin
Davey_guan4-Mar-12 15:40
memberDavey_guan4-Mar-12 15:40 
Generalits nice Pin
Pranay Rana30-Dec-10 1:02
professionalPranay Rana30-Dec-10 1:02 
Questionhow about calling Form.Show in Main before Application.Run Pin
sharapanoff20-Sep-10 1:30
membersharapanoff20-Sep-10 1:30 
AnswerRe: how about calling Form.Show in Main before Application.Run Pin
Vladimir Knyazkov20-Sep-10 23:29
professionalVladimir Knyazkov20-Sep-10 23:29 
GeneralMy vote of 5 Pin
XChronos6-Sep-10 16:15
memberXChronos6-Sep-10 16:15 
GeneralRe: My vote of 5 Pin
Vladimir Knyazkov6-Sep-10 23:31
professionalVladimir Knyazkov6-Sep-10 23:31 
GeneralMy vote of 1 Pin
Eric Xue (brokensnow)3-Sep-10 19:01
memberEric Xue (brokensnow)3-Sep-10 19:01 
GeneralRe: My vote of 1 Pin
Vladimir Knyazkov4-Sep-10 4:01
professionalVladimir Knyazkov4-Sep-10 4:01 
GeneralRe: My vote of 1 Pin
Irwan Hassan8-Sep-10 6:36
memberIrwan Hassan8-Sep-10 6:36 
GeneralRe: My vote of 1 Pin
JTRizos6-May-11 9:09
memberJTRizos6-May-11 9:09 
GeneralSplash in background Pin
nedel2-Sep-10 23:57
membernedel2-Sep-10 23:57 
GeneralRe: Splash in background Pin
Vladimir Knyazkov3-Sep-10 1:15
professionalVladimir Knyazkov3-Sep-10 1:15 
GeneralRe: Splash in background Pin
agovorovsky13-Sep-10 18:57
memberagovorovsky13-Sep-10 18:57 
GeneralMy vote of 3 Pin
maq_rohit2-Sep-10 7:21
professionalmaq_rohit2-Sep-10 7:21 
GeneralRe: My vote of 3 Pin
Vladimir Knyazkov2-Sep-10 20:19
professionalVladimir Knyazkov2-Sep-10 20:19 
GeneralRe: My vote of 3 Pin
Vladimir Knyazkov3-Sep-10 1:12
professionalVladimir Knyazkov3-Sep-10 1:12 
GeneralOK job. Pin
Dave Kreskowiak2-Sep-10 4:27
mveDave Kreskowiak2-Sep-10 4:27 
GeneralRe: OK job. [modified] Pin
Vladimir Knyazkov2-Sep-10 4:51
professionalVladimir Knyazkov2-Sep-10 4:51 
I will not argue. It makes no sense - any of the technologies of cryptography has its pluses and minuses. But in this case - MD5 enough. You could apply to the class System.Security and chose the cryptographic protection, which you need.

modified on Thursday, September 2, 2010 12:07 PM

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190114.1 | Last Updated 8 Sep 2010
Article Copyright 2010 by Vladimir Knyazkov
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid