当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Word.InRange方法代码示例

本文整理汇总了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;
        }
开发者ID:plutext,项目名称:OpenDoPE-Model,代码行数:46,代码来源:ContentControlMaker.cs


注:本文中的Microsoft.Office.Interop.Word.InRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。