Example #1
0
        public void PaintSelf(
            Graphics graphics,
            Point parentLocation,
            HighlightOptions highlightOptions,
            RectangularSelection selection,
            SelectionOptions selectionOptions)
        {
            var contentArea  = getArea(parentLocation, Location, Padding);
            var completeArea = getArea(parentLocation, Location, new Padding(0));

            if (Image != null)
            {
                paintImage(graphics, contentArea);
            }

            if (!string.IsNullOrEmpty(DataText) && contentArea.Width > 0 && contentArea.Height > 0)
            {
                bool isTextSelecting = selection.Selecting && completeArea.Contains(selection.Start);

                paintText(
                    graphics,
                    highlightOptions,
                    selection,
                    selectionOptions,
                    contentArea,
                    isTextSelecting);
            }
        }
Example #2
0
        private void paintText(
            Graphics graphics,
            HighlightOptions highlightOptions,
            RectangularSelection selection,
            SelectionOptions selectionOptions,
            Rectangle contentArea,
            bool isTextSelecting)
        {
            _paintInProgress = true;

            if (selection.Selecting)
            {
                TextSelection.Clear();
            }

            var context = new RichTextRenderContext
            {
                Text            = DataText,
                TextSelection   = TextSelection.Clone(),
                HighlightRanges = HighlightRanges,
                Graphics        = graphics,
                Rect            = contentArea,
                HorizAlignment  = HorizontalAlignment,
                Font            = Font,
                ForeColor       = ForeColor,

                HighlightContextColor = highlightOptions.HighlightContextColor,
                HighlightColor        = highlightOptions.HighlightColor,
                HighlightBorderColor  = highlightOptions.HighlightBorderColor,
                HighlightBorderWidth  = 1f
            };

            if (isTextSelecting)
            {
                context.Selecting      = true;
                context.SelectionStart = selection.Start;
                context.SelectionEnd   = selection.End;
            }

            context.SelectionBackColor = selectionOptions.BackColor;
            context.SelectionForeColor = selectionOptions.ForeColor;
            context.SelectionAlpha     = selectionOptions.Alpha;

            RichTextRenderer.Render(context, _iconRecognizer);

            if (selection.Selecting)
            {
                TextSelection.SetSelection(context.TextSelection);
            }

            _paintInProgress = false;
        }