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


C# TextRange.GetBackgroundAsConsoleColor方法代码示例

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


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

示例1: GetBufferContents

        public BufferCell[,] GetBufferContents(Rectangle rectangle)
        {
            BufferCell[,] bufferCells = new BufferCell[(rectangle.Top - rectangle.Bottom), (rectangle.Right - rectangle.Left)];
            try
            {
                var cur = (int)
                   ((Next.ElementEnd.GetCharacterRect(LogicalDirection.Backward).Bottom + ScrollViewer.ContentVerticalOffset)
                        / (double.IsNaN(Document.LineHeight) ? Document.FontSize : Document.LineHeight));
                int count;
                var nextContextPosition = Next.ElementEnd.GetNextContextPosition(LogicalDirection.Backward);
                var start = nextContextPosition?.GetLineStartPosition(rectangle.Bottom - cur, out count);
                if (start != null)
                {
                    // for each line
                    for (var ln = 0; ln <= rectangle.Top - rectangle.Bottom; ln++)
                    {
                        // Resharper is being stupid here, these can't actually be null:
                        Debug.Assert(start != null, "start != null");
                        var next = start.GetLineStartPosition(1);
                        start = start.GetPositionAtOffset(rectangle.Left);
                        // Resharper is being stupid here, these can't actually be null:
                        Debug.Assert(start != null, "start != null");
                        Debug.Assert(next != null, "next != null");
                        // if there's text on this line after that char, there's no output
                        if (start.GetOffsetToPosition(next) <= 0) { continue; }

                        var end = start.GetPositionAtOffset(1);
                        Debug.Assert(end != null, "end != null");

                        // for each character in the line
                        int c = 0, width = rectangle.Right - rectangle.Left;
                        while (end.GetOffsetToPosition(next) <= 0 && c < width)
                        {
                            var range = new TextRange(start, end);
                            bufferCells[ln, c++] = new BufferCell(
                                                            range.Text[0],
                                                            range.GetBackgroundAsConsoleColor(),
                                                            range.GetForegroundAsConsoleColor(),
                                                            BufferCellType.Complete);

                            end = end.GetPositionAtOffset(1);
                        }

                        // for the whitespace ta the end of the line
                        for (; c < width; c++)
                        {
                            bufferCells[ln, c] = new BufferCell(' ', ForegroundColor, BackgroundColor, BufferCellType.Complete);
                        }
                        start = next;
                    }
                }
            }
            catch (Exception ex)
            {
                Write(ConsoleBrushes.ErrorForeground, ConsoleBrushes.ErrorBackground, ex.Message);
            }
            return bufferCells;
        }
开发者ID:Jaykul,项目名称:PoshConsole,代码行数:58,代码来源:ConsoleControl.BufferSize.cs


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