c# - 如何在 Windows Installer 自定义对话框中将字段设置为必填

标签 c# winforms windows-installer setup-project orca

我最近为我的 C# .NET Windows 窗体应用程序创建了一个安装项目。

在我的用户界面编辑器中我有:

- Start
  - Welcome
  - Textboxes (A)
  - Installation Folder
  - Confirm Installation

文本框 (A) 对话框中,我有一个我想强制设置的编辑字段。

我该怎么做?我已经下载了 Orca 编辑器。有没有一种简单的方法可以使用它来做到这一点?

这是我希望实现的两个目标(至少是目标 1):

  1. 根据编辑标签非空启用/禁用下一步按钮
  2. 是否可以在点击下一步按钮后验证内容?

感谢任何帮助。

谢谢!

最佳答案

Windows Installer 对话框定义位于 VS 已部署版本的 IDE 文件夹下的 CommonExtensions\Microsoft\VSI\bin\VsdDialogs 文件夹中,例如,对于 VS 2017,它是这样的:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\VSI\bin\VsdDialogs\

在该文件夹中,转到 01033 文件夹,运行 orca以管理员身份更改 VsdCustomText1Dlg.wid 文件,该文件用于 Textboxes (A)

Note 1: You can create a new windows installer dialog by copying that file and renaming it to MyCustomDialog.wid. Then open it in orca and go to ModuleDialog table and change the DisplayName to My Custom Dialog. Make sure you copy the file in both 1033 and 0. Then in VS, you can add an instance of this dialog using User Interface Editor of Setup project.

Note 2: You can also edit the msi file using Orca and edit the control conditions, but if you do so, then every time you build the setup project, you need to repeat editing of the msi file. So editing .wid makes more sense.

Note 3: Combining conditions of fields using AND and OR is possible as well. For more information, take a look at ControlCondition Table and Conditional Statement Syntax

在 Windows Installer 自定义对话框中强制设置一个字段

要使 Edit1 值成为必需值并启用或禁用 Next 按钮:

  1. 以管理员身份运行orca

  2. 打开用于添加自定义对话框的 wid 文件。

  3. ControlCondition 中,除了现有行之外,添加以下行:

     ┌──────────────┬──────────────┬──────────────┬──────────────┐
     │ Dialog_      │ Control_     │ Action       │ Condition    │
     ├──────────────┼──────────────┼──────────────┼──────────────┤
                                  ...
     │ CustomTextA  │ NextButton   │ Disable      │ EDITA1=""    │
     │ CustomTextA  │ NextButton   │ Enable       │ EDITA1<>""   │
     └──────────────┴──────────────┴──────────────┴──────────────┘
    
  4. 保存文件并确保 10330 文件夹中有相同的文件。

  5. 关闭Orca

  6. 重建安装项目。

  7. 安装它。

结果你会看到这样的行为:

enter image description here

关于c# - 如何在 Windows Installer 自定义对话框中将字段设置为必填,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59437532/

相关文章:

c# - .NET CORE 中的 "Specified cipher mode is not valid for this algorithm"但在 .NET Standard 中工作

c# - generic 和 double 操作

c# - MVC 5 - 尝试通过编辑操作修改图像失败

c# - 如何调整 c# 标记图像的大小?

c# - 带有 ProgressBar 的 BackgroundWorker - 跨线程操作无效

windows - Windowsinstaller 中的 Autogen guid (*) 导致 ICE08 错误

windows-installer - 安装过程中出现错误代码 2753

c# - 不能向没有列的 DataGridView 控件添加任何行。必须先添加列

c# - Windows 窗体应用程序中的闪烁

windows-installer - WinUSB 驱动程序在 XP 上安装失败(在 Win7 上工作正常)