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


C# ITextView.Contains方法代码示例

本文整理汇总了C#中ITextView.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ITextView.Contains方法的具体用法?C# ITextView.Contains怎么用?C# ITextView.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextView的用法示例。


在下文中一共展示了ITextView.Contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Find

        internal static ITextRange Find(FindToolBar findToolBar, TextEditor textEditor, ITextView textView, ITextView masterPageTextView)
        {
            string searchText;
            FindFlags findFlags;
            ITextContainer textContainer;
            ITextRange textSelection;
            ITextPointer contentStart;
            ITextPointer contentEnd;
            ITextPointer startPointer = null;
            ITextRange findResult = null;

            Invariant.Assert(findToolBar != null);
            Invariant.Assert(textEditor != null);

            // Set up our FindOptions from the options in the Find Toolbar.
            findFlags = FindFlags.None;
            findFlags |= (findToolBar.SearchUp ? FindFlags.FindInReverse : FindFlags.None);
            findFlags |= (findToolBar.MatchCase ? FindFlags.MatchCase : FindFlags.None);
            findFlags |= (findToolBar.MatchWholeWord ? FindFlags.FindWholeWordsOnly : FindFlags.None);
            findFlags |= (findToolBar.MatchDiacritic ? FindFlags.MatchDiacritics : FindFlags.None);
            findFlags |= (findToolBar.MatchKashida ? FindFlags.MatchKashida : FindFlags.None);
            findFlags |= (findToolBar.MatchAlefHamza ? FindFlags.MatchAlefHamza : FindFlags.None);

            // Get the text container for our content.
            textContainer = textEditor.TextContainer;
            textSelection = textEditor.Selection;

            // Initialize other Find parameters
            searchText = findToolBar.SearchText;
            CultureInfo cultureInfo = GetDocumentCultureInfo(textContainer);

            // The find behavior below is defined in section 2.2.3 of this spec:
            // http://d2/DRX/Development%20Documents/02.01.00%20-%20UI%20Design.DocumentViewer.mht

            // Determine if we have a starting selection
            if (textSelection.IsEmpty)
            {
                if (textView != null && !textView.IsValid)
                {
                    textView = null;
                }

                // Determine if the IP/Selection is in view.
                if (textView != null && textView.Contains(textSelection.Start))
                {
                    // Case 1: Selection is empty and IP is currently visible.
                    // Search from this IP to the start/end of the document.

                    //We treat the start of the selection as the IP.
                    contentStart = findToolBar.SearchUp ? textContainer.Start : textSelection.Start;
                    contentEnd = findToolBar.SearchUp ? textSelection.Start : textContainer.End;
                }
                else
                {
                    // Case 4: Selection is empty and IP is not currently visible.
                    // Search from the top of the current TextView to the end of the document,
                    // if searching down. If searchind up, search from the start of the document
                    // to the end position of the current TextView.
                    if (masterPageTextView != null && masterPageTextView.IsValid)
                    {
                        foreach (TextSegment textSegment in masterPageTextView.TextSegments)
                        {
                            if (textSegment.IsNull)
                            {
                                continue;
                            }

                            if (startPointer == null)
                            {
                                // Set initial masterPointer value.
                                startPointer = !findToolBar.SearchUp ? textSegment.Start : textSegment.End;
                            }
                            else
                            {
                                if (!findToolBar.SearchUp)
                                {
                                    if (textSegment.Start.CompareTo(startPointer) < 0)
                                    {
                                        // Start is before the current masterPointer
                                        startPointer = textSegment.Start;
                                    }
                                }
                                else
                                {
                                    // end is after than the current masterPointer
                                    if (textSegment.End.CompareTo(startPointer) > 0)
                                    {
                                        startPointer = textSegment.End;
                                    }
                                }
                            }
                        }
                    }

                    if (startPointer != null)
                    {
                        // Now build the content range from that pointer to the start/end of the document.
                        // Set content start/end pointer to the content of the find document
                        contentStart = findToolBar.SearchUp ? textContainer.Start : startPointer;
                        contentEnd = findToolBar.SearchUp ? startPointer : textContainer.End;
//.........这里部分代码省略.........
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:DocumentViewerHelper.cs


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