本文整理汇总了C#中Microsoft.Office.Interop.Word.InRange方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.InRange方法的具体用法?C# Microsoft.Office.Interop.Word.InRange怎么用?C# Microsoft.Office.Interop.Word.InRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Word.InRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getActiveContentControl
/// <summary>
/// Return the content control containing the cursor, or
/// null if we are outside a content control or the selection
/// spans the content control boundary
/// </summary>
/// <param name="docx"></param>
/// <param name="selection"></param>
/// <returns></returns>
public static Word.ContentControl getActiveContentControl(Word.Document docx, Word.Selection selection)
{
//Word.Selection selection = Globals.ThisAddIn.Application.Selection;
// Word.ContentControls ccs = selection.ContentControls;
// only has a value if the selection contains one or both *ends* of a ContentControl
// so how do you expand a selection to include the entire content control?
// or can we ask whether a content control is active,
// ie the selection is in it?
// or iterate through the content controls in the active doc,
// asking whether their range contains my range? YES
// Hmmm... what about nesting of cc?
Word.ContentControl result = null;
foreach (Word.ContentControl ctrl in docx.ContentControls)
{
int highestCount = -1;
if (selection.InRange(ctrl.Range))
{
//diagnostics("DEBUG - Got control");
log.Debug("In control: " + ctrl.ID);
int parents = countParent(ctrl);
if (parents > highestCount)
{
log.Debug(".. highest ");
result = ctrl;
highestCount = parents;
}
}
// else user's selection is totally outside the content control, or crosses its boundary
}
//if (stateDocx.InControl == true)
return result;
}