C# 自定义操作窗口表单焦点问题 [英] C# custom action windows form focused issue

查看:57
本文介绍了C# 自定义操作窗口表单焦点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我使用 Visual Studio 安装项目将 C# 应用程序之一部署到客户端 Windows 服务器.安装应用程序时,我还需要在服务器中设置计划任务为此,我在安装项目中使用了自定义操作功能.我所做的是创建了一个带有输入字段和确定"按钮的 Windows 窗体,一旦用户输入值并单击确定"按钮,就会创建任务.我在 InstallCommit 步骤中添加了这个自定义任务 Custom Action.

Background: I used Visual Studio setup project to deploy one of C# application to client windows server. While installing the application I need to setup a scheduled task in the server as well For this I used a Custom Action feature in the setup project. What I did is created a windows form with input fields and "ok" button and once user enter values and click on the "ok" button task will be created. I added this custom task in Install and Commit steps in Custom Action.

问题: 一切正常,但是当从显示创建的窗口时,即使我使用 showDialog 方法来显示表单,它也失去了焦点.因此,主设置窗口始终处于活动状态,用户不会在后台看到弹出窗体(见附图).但我可以单击弹出窗口并激活它.我也尝试过 SetActiveWindow 方法,但到目前为止效果不佳.

Issue : Everything works fine but when the created windows from shows, it lost the focuses even I used showDialog method to show the form. So always main setup window will active and users not see the popup form in background (see the attached image).But I can click on the popup window and make it activate. I tried with SetActiveWindow method also but no good result so far.

我需要的是激活弹出窗口,直到用户操作(默认 showDialog 行为).所以在这里我正在寻找任何帮助.

Simple what I need is to activate the popup window untill user action (default showDialog behavior). So here I'm looking for any help.

推荐答案

如果您想在 MSI 部署期间使用自定义 UI 获取用户输入,最好的方法是创建 .wid 扩展文件.这是您在 MSI 安装过程中看到的 UI 文件类型(在其中选择安装路径等).尽管 Visual Studio 没有创建这些 UI 文件的功能,但您可以使用 Microsoft 工具来创建这些文件.最好的工具之一是 Orac.

If you want to get user input using custom UI during the MSI deployment best approach is to create the .wid extension files. this is the type of UI files that you see during the MSI installation(where you select the installation path etc). Enough though visual studio doesn't have features to create these UI files there are Microsoft tools you can use to create these files. One of the best tool is Orac.

创建 UI 文件后,必须将该文件放在 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\Deployment\VsdDialogs\1033 (这是 MSI 从中选择默认 UI 文件的地方)

Once you create the UI file, you have to place the file under C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\Deployment\VsdDialogs\1033 (it's where MSI picks the default UI files from)

之后,您应该能够选择自定义 UI 并在安装周期的任何阶段(安装前、安装后、安装后等)注入它.然后您可以将用户在文本字段中输入的值作为安装程序类的参数传递.然后您可以使用上下文参数读取安装程序类中的值.

After that you should be able to select your custom UI and inject it during any phase of installation cycle(beforeinstall, install, afterinstall etc). Then you can pass the value user has entered into the text field as a argument for installer class. Then you can read the value within the installer class using context parameter.

string value = Context.Parameters["ParameterName"];

这篇关于C# 自定义操作窗口表单焦点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆