Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 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 Reply

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");
            }
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...