可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
[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?
回答1:
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()?
回答2:
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.
回答3:
If you want to have complete control over installer user interface for branding or custom dialogs and don't want to use installer builder software like InstallShield then you can create a C++ application to serve as shell for Windows Installer - there is no need to implement installer actions such as copying files by yourself.
Windows Installer has API for such purpose. With function MsiSetExternalUIRecord you can provide a callback to capture installer notifications such as messages and progress updates.
回答4:
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.
回答5:
Top most won't work. Simply make the form to be displayed in the custom action larger than the MSI installer form.
回答6:
Try the link below,
http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/158ad5bd-d3f7-4a21-8ebe-341e9741810a
回答7:
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);
}
回答8:
You can use form option TopMost and Focus method. But there much better way. You can get installer process, then get it window handler and then use it as parameter in ShowDialog method::
var proc = Process.GetProcessesByName("msiexec").FirstOrDefault(p => p.MainWindowTitle == "Name of product");
var formResult = proc != null
? form.ShowDialog(new WindowWrapper(proc.MainWindowHandle))
: form.ShowDialog();
WindowWrapper is something like this:
public class WindowWrapper : IWin32Window
{
private readonly IntPtr hwnd;
public IntPtr Handle {
get { return hwnd; }
}
public WindowWrapper(IntPtr handle) {
hwnd = handle;
}
}
回答9:
Call Minimize and Restore/show methods of the form, this fix your problem.
回答10:
Call this.focus()
in your form.OnLoad
method.
That makes it show up in front of the installer. Simple fix.