Click here to Skip to main content
13,087,235 members (55,537 online)
Rate this:
Please Sign up or sign in to vote.

i am developing an application for which i have created a database of serial numbers to activate the product. When your enters the correct serial number then it registers the product and provide access to the product but when the user close the application and open the application it again asks for serial number. Is there any way that once user enters the correct serial then it will not ask for serial when the application is closed and opened again!
Posted 14-Aug-14 8:04am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Your application likely has a Program.cs file or similar with statement like:

System.Windows.Forms.Application.Run ( new Form1() ) ;

You should be able to change it to something along the lines of:

if ( app is not registered ) System.Windows.Forms.Application.Run ( new registrationform() ) ;
if ( app is registered ) System.Windows.Forms.Application.Run ( new mainform() ) ;

The test for whether or not the app is registered will likely be implemented in the DAL.

Be sure to have the data access code in a separate class; not in the form.
Sergey Alexandrovich Kryukov 14-Aug-14 23:01pm
That is correct, a 5. I would only add that this is not the only way to show identical behavior, just because the role main (starting) form makes little difference: when it is closed, application is closed.
So, it's possible to close application by handling FormClosed of some other form, which would play the role similar to the starting form (which can be, say, hidden). What is simpler, depends on the application.
PIEBALDconsult 15-Aug-14 10:51am
Yes, many ways to reach the goal. I think this way yields a better separation of concerns.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Once the key is entered correctly, you can mark the application as registered in a database or any other store like registry.
Next time when the user opens the application, check this storage for registered status and then decide whether the serial box needs to be displayed or not.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Check out System.Windows.Forms.ApplicationContext[^]

I use this class to first show a login form, and then the main form.

static void Main()
  var loginSeq = new LoginSequence();

public class LoginSequence : ApplicationContext
        private LoginForm _login;
        // Ctor - Show LoginForm first.
        public LoginSequence()
            _login = new LoginForm();
            _login.Closed += LoginFormClosed;
        /// <summary>
        /// LoginForm has closed
        /// </summary>
        private void LoginFormClosed(object sender, EventArgs e)
            // Check LoginFrom result
            if (_login.DialogResult == DialogResult.OK)
                // Valid
                _login.Closed -= LoginFormClosed;
                _login = null;
                // Show MainForm
                MainForm = new MainForm();
                // Invalid user login

And it is work fine for my use.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 15 Aug 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100