Example #1
0
    private void PaintLineHighlight()
    {
        using (Graphics g = this.CreateGraphics())
        {
            Color      color           = Color.Lavender;
            Pen        highlight_pen   = new Pen(Color.Lavender);
            Pen        clear_pen       = new Pen(this.BackColor);
            SolidBrush highlight_brush = new SolidBrush(Color.FromArgb(64, color.R, color.G, color.B));
            SolidBrush clear_brush     = new SolidBrush(this.BackColor);

            // index of the current line
            int index = this.GetFirstCharIndexOfCurrentLine();

            // rectangle to specify which region to paint too
            Rectangle rect = new Rectangle();

            // specify dimensions
            rect.X      = 0;
            rect.Y      = this.GetPositionFromCharIndex(index).Y;
            rect.Width  = this.GetHorizontalScrollBarWidth();
            rect.Height = Convert.ToInt32(this.Font.Height * this.ZoomFactor);

            // this will always be true unless the current line remains the same
            if (!(mLastHighlight.mCharIndex == index) && !(mLastHighlight.mRectangle == rect))
            {
                // remove the last highlight. regardless of the brush specified, white is always applied, and the text is painted over
                g.DrawRectangle(clear_pen, mLastHighlight.mRectangle);
                g.FillRectangle(clear_brush, mLastHighlight.mRectangle);
                // apply highlight to the current line
                g.DrawRectangle(highlight_pen, rect);
                g.FillRectangle(highlight_brush, rect);
            }

            mLastHighlight = new LastHighlight(index, rect);
        }
    }
Example #2
0
    private void PaintLineHighlight()
    {
        using (Graphics g = this.CreateGraphics())
        {
            Color color = Color.Lavender;
            Pen highlight_pen = new Pen(Color.Lavender);
            Pen clear_pen = new Pen(this.BackColor);
            SolidBrush highlight_brush = new SolidBrush(Color.FromArgb(64, color.R, color.G, color.B));
            SolidBrush clear_brush = new SolidBrush(this.BackColor);

            // index of the current line
            int index = this.GetFirstCharIndexOfCurrentLine();

            // rectangle to specify which region to paint too
            Rectangle rect = new Rectangle();

            // specify dimensions
            rect.X = 0;
            rect.Y = this.GetPositionFromCharIndex(index).Y;
            rect.Width = this.GetHorizontalScrollBarWidth();
            rect.Height = Convert.ToInt32(this.Font.Height * this.ZoomFactor);

            // this will always be true unless the current line remains the same
            if (!(mLastHighlight.mCharIndex == index) && !(mLastHighlight.mRectangle == rect))
            {
                // remove the last highlight. regardless of the brush specified, white is always applied, and the text is painted over
                g.DrawRectangle(clear_pen, mLastHighlight.mRectangle);
                g.FillRectangle(clear_brush, mLastHighlight.mRectangle);
                // apply highlight to the current line
                g.DrawRectangle(highlight_pen, rect);
                g.FillRectangle(highlight_brush, rect);
            }

            mLastHighlight = new LastHighlight(index, rect);
        }
    }