Custom Installer in .Net showing Form behind insta

2020-02-01 05:08发布

[RunInstaller(true)]
public partial class Installer1 : Installer
{
    public Installer1()
    {
        InitializeComponent();
    }

    public override void Install(System.Collections.IDictionary stateSaver)
    {
        base.Install(stateSaver);
    }
    private void Installer1_AfterInstall(object sender, InstallEventArgs e)
    {
        Form1 topmostForm = new Form1();
        topmostForm.BringToFront();
        topmostForm.TopMost = true;            
        topmostForm.ShowDialog();
  } }

I need to display the topmostForm in front of the default Windows Installer UI. The above is sample code inside my CustomAction that I am using to create a Form. Setting the TopMost property or using ShowDialog is not helping. Is there any other solution to make my form the top most and focussed?

10条回答
淡お忘
2楼-- · 2020-02-01 05:15

Call Minimize and Restore/show methods of the form, this fix your problem.

查看更多
Anthone
3楼-- · 2020-02-01 05:16

although i'm not wuite sure what exactly you're asking for, using WiX for building windows installers is the prefered way to go. There you can build your forms and custom actions and pretty much anything else.

查看更多
做个烂人
4楼-- · 2020-02-01 05:20

I tried the same and I can see the form. The only different I can see is you are missing base.OnAfterInstall(savedState); in your code.

And if it still doesn't show up the try putting just MessageBox to see if your installer is hooked or not with setup project

    protected override void OnAfterInstall(IDictionary savedState)
    {
        // message box to test
        MessageBox.Show("test");
        Verify topmostForm = new Verify();
        topmostForm.BringToFront();
        topmostForm.TopMost = true;
        topmostForm.ShowDialog();

      //this line is missing in your code

       base.OnAfterInstall(savedState);
    }
查看更多
姐就是有狂的资本
5楼-- · 2020-02-01 05:24

If you want to show your own UI in the installer, you won't be able to use a setup and deployment project, because it lacks the features necessary to implement that. Consider using an installer toolkit like WiX or Inno Setup instead.

Concerning the first part of your question, are you passing the custom dialog box in the owner argument to MessageBox.Show()?

查看更多
Evening l夕情丶
6楼-- · 2020-02-01 05:25

Top most won't work. Simply make the form to be displayed in the custom action larger than the MSI installer form.

查看更多
▲ chillily
7楼-- · 2020-02-01 05:27

Dialogs created by custom actions are always displayed behind the installation dialogs on newer Windows versions (Vista and Windows 7). This is because Windows prevents applications to move a window on top of all other windows. Think how virus popups would fill up the screen on older Windows versions.

Instead, a newly created dialog is displayed in the background and it's title bar button (if it has one) flashes.

The correct solution for what you want is creating a dialog in your MSI package and using it instead of the custom action.

查看更多
登录 后发表回答