Reputation: 5176
I have an installer for my C# project, which requires the user to enter a license before continuing with the install. I get the license from the user by instantiating a form and then calling ShowDialog on it.
My problem is that the user may click on something else during the install. This means that the dialog may be hidden, and the installation will not proceed, until the user discovers the dialog on the taskbar. I would like to display the license dialog topmost, but I don't know how to do it. Can I somehow make the install application topmost from my BeforeInstall event handler? The installer runs with administrator rights.
Edit: It seems I was too hasty in accepting an answer. I now have code such as the following in my BeforeInstall event handler:
using (var licenseDlg = new LicenseDialog())
{
licenseDlg.TopMost = true;
var result = licenseDlg.ShowDialog();
...
The behavior is the following:
If I don't do anything else, then at some point the license window will pop up over my cmd window. However, if I type anything at the cmd prompt, at a rate of about 1 click per second, then the license window will not pop up, it will only show on the task bar. I would like to always have the license window pop up, even when there is activity in other windows.
Upvotes: 0
Views: 450
Reputation: 3624
Use the TopMost property !
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost.aspx
Upvotes: 1
Reputation: 16209
When you're opening a form in the BeforeInstall
event, simply set TopMost
to true.
var licenseForm = new Form
{
TopMost = true
};
Upvotes: 3