如何以编程方式启用“选项...” MS Word 打印设置对话框中的按钮
我正在尝试在 Microsoft Word 2003 的 VSTO 插件中显示 MS Word“打印设置”对话框。我可以显示该对话框,但对话框左下角的选项按钮始终处于禁用状态,如下所示捕获。
到目前为止我所做的相关代码是:
private void printSetup_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
Dialog dialog = App.Dialogs[WdWordDialog.wdDialogFilePrintSetup];
Object missing = Type.Missing;
dialog.Show(ref missing); // Note that the param is TimeOut
}
谁能告诉我我必须做什么才能启用“选项”按钮?我知道这是可以完成的,因为我们正在替换用于在 VBA 中执行此操作的模板,并且该按钮已在那里启用...
问候, 本
I'm trying to display the MS Word "Print Setup" dialog in a VSTO AddIn for Microsoft Word 2003. I can display the dialog box, but the options button at the bottom left corner of the dialog is always disabled as per the following screen capture.
The relevant code for what I've done so far is:
private void printSetup_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
Dialog dialog = App.Dialogs[WdWordDialog.wdDialogFilePrintSetup];
Object missing = Type.Missing;
dialog.Show(ref missing); // Note that the param is TimeOut
}
Can anyone tell me what I have to do to enable the Options button? I know it can be done because we are replacing a template that used to do this in VBA and the button is enabled there...
Regards,
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对话框的属性只能通过后期绑定获得,并且由于您使用的是 C#,因此您需要使用
InvokeMember
来获取和设置与您正在使用的对话框相关的值。从 WdWordDialog Enumeration 的文档中,您知道对于
WdWordDialog.wdDialogFilePrintSetup
对话框的Options
属性可用。该链接适用于 Office 2007,但对于当前的情况来说,它应该足够了。有了这些知识,您可以执行以下操作来设置对话框属性值:
The properties of dialog boxes are only available through late-binding and since you are using C# you'll need to use
InvokeMember
to get and set values related to the dialog you are working with.From the documentation of the WdWordDialog Enumeration you know that for the
WdWordDialog.wdDialogFilePrintSetup
dialog anOptions
attribute is available. The link is for Office 2007, but for the case in hand it should suffice.With this knowledge you can do something like this to set the dialog attribute value:
我现在从同事那里得到了一个有效的解决方案。
虽然它不能解决从任何 VSTO C# 代码启动此对话框的更一般情况,但它确实可以通过单击工具栏按钮正确启动此对话框(这就是我们正在尝试做的事情)。所以这为我们解决了问题。
我现在实际上认为这是 MS Word 的一个错误(功能?),并且没有任何通用方法可以从代码中显示此对话框并启用“选项...”按钮。我认为只有当 MS Word 自动调用对话框时它才能工作,因为它作为内置控件连接到 CommandBar。我在 VBA 以及 VSTO 中看到了相同的行为,这往往支持这是一个字限制/错误的理论。
因此,我们以前有这样的代码:
当修改为通过将 Controls.Add() 的第二个参数 (Id) 从 Type.Missing 更改为 511(文件打印设置对话框的 ID)来调用内置控件时,如下所示“选项...”按钮如人们所期望的那样启用:
希望这可以帮助遇到此问题的其他人。
I now have a solution that works that I got from a colleague.
While it doesn't solve the more general case of launching this dialog from any VSTO C# code, it does work for launching this dialog correctly as a result of clicking a toolbar button (which is what we are trying to do). So this fixes the problem for us.
I'm actually of the opinion now that this is a bug (feature?) of MS Word and that there isn't any general way of displaying this dialog from code and having the "Options..." button enabled. I think it can only work if the dialog is invoked automatically by MS Word due to it being hooked up to the CommandBar as a built-in control. I've seen the same behaviour in VBA as well as through VSTO which tends to support the theory that it's a Word limitation/bug.
So we previously had code like this:
And when modified to call the built-in control by changing the second argument (Id) to Controls.Add() from Type.Missing to 511 (the ID for the File Print Setup dialog) like this the "Options..." button is enabled like one would expect:
Hopefully this helps others who run into this problem.