Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

c# - Showing custom form before installation?

I am creating a setup for windows application, i want to show a form when user clicks on setup. That form will ask for password to the user.

Right password will lead to the proper installation of the setup otherwise setup installation will be cancelled.

How to do this, if some one provide a link for it.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Following would be the easiest approach,

  1. First create a Windows Form which allows the user to enter password.
  2. Windows Form should have the necessary implementation to validate the password.
  3. Expose a public boolean property within windows form which should say whether password it valid or not.
  4. Now you have to add a new class library project to your solution(or you an use existing project).
  5. Add a Installer Class to your new project.
  6. Within installer class's Install method you have to open created windows form (please note windows form can not be opened as a modal pop up here).
  7. Now windows form will get user input and validate it and set the boolean value to puplic property.
  8. Within installer class based on the boolean value you will either continue the installation or abort.

Installer classe's Install()

public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);

            Form1 validationForm = new Form1();
            validationForm.ShowDialog();

            if (!validationForm.IsValidPassword)
            {
                throw new Exception("Invalid Password. Please enter valid password to continue installation");
            }
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...