1

我正在开发一个 VSTO 项目,并希望在隐藏模式下使用Word 对话框,就像下面的代码一样:

来自 MSDN 的代码

dynamic dialog = Application.Dialogs[Word.WdWordDialog.wdDialogFilePageSetup];
dialog.PageWidth = "3.3\"";
dialog.PageHeight = "6\"";
dialog.TopMargin = "0.71\"";
dialog.BottomMargin = "0.81\"";
dialog.LeftMargin = "0.66\"";
dialog.RightMargin = "0.66\"";
dialog.HeaderDistance = "0.28\"";
dialog.Orientation = "0";
dialog.DifferentFirstPage = "0";
dialog.FirstPage = "0";
dialog.OtherPages = "0";

// Apply these settings only to the current selection with this line of code:
dialog.ApplyPropsTo = "3";

// Apply the settings.
dialog.Execute(); 

我想实现另一个 diaglog wdDialogEditFind,但方法和属性是未知的。然后使用反射来检索它们(后期绑定)。但没有找到有用的方法。

Word.Dialog dlg = this.Application.Dialogs[Word.WdWordDialog.wdDialogEditFind];

System.Type t = dlg.Type.GetType();
System.Reflection.MemberInfo[] memInfo = t.GetMembers();
    
string str = "";
foreach (System.Reflection.MemberInfo m in memInfo)
    str += m.Name + "\n";
4

1 回答 1

1

MS Word interop 对您隐藏这些成员,因为它依赖于COM RCW。反射不能用于遍历属性,因为它们不是为Dialog基类型定义的。如果您想知道可用的属性 - 请参阅此 MSDN 参考以了解wdDialogEditFind.

内置对话框参数wdDialogEditFind来自 MSDN

Find, Replace, Direction, MatchCase, WholeWord, PatternMatch, SoundsLike, FindNext, ReplaceOne, ReplaceAll, Format, Wrap, FindAllWordForms, MatchByte, FuzzyFind, Destination, CorrectEnd, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl

如果您坚持要了解 COM 方法和属性 - 您可以深入了解COM 类型IDispatch并从中筛选。

于 2012-09-13T17:02:12.187 回答