• HOME
  • PRODUCTS
  • DEMOS
  • BUY
  • BLOG
  • FORUM
  • DOCUMENTATION
  • ABOUT
  • FREE EVALUATION
Search Results for

    Show / Hide Table of Contents

    Painter Property

    Painter

    Represents an object that implements IPainter interface used to draw control's text.

    Declaration
    [Browsable(false)]
    public virtual IPainter Painter { get; }
    Property Value
    Type Description
    IPainter
    Implements
    ISyntaxEdit.Painter
    Remarks

    SyntaxEdit control uses GDI to draw all graphical primitives, such as text images and geometric shapes. You can use this drawing surface to customize paintings using a custom drawing.

    Examples

    Here is how to use a Painter in the C# code:

    public partial class Form1 : Form
    {
        private Alternet.Syntax.Parsers.Roslyn.CsParser csParser1 = new Alternet.Syntax.Parsers.Roslyn.CsParser();
    
        private void Form1_Load(object sender, EventArgs e)
        {
            var syntaxEdit1 = new Alternet.Editor.SyntaxEdit(this.components);
            syntaxEdit1.CustomDraw += SyntaxEdit1_CustomDraw;
            syntaxEdit1.Outlining.AllowOutlining = true;
        }
    
        private void SyntaxEdit1_CustomDraw(object sender, Alternet.Editor.CustomDrawEventArgs e)
        {
            if ((csParser1.Repository == null) || csParser1.Repository.Document == null)
                return;
    
            var text = this.csParser1.Repository.Document.GetTextAsync().Result;
            if (text == null)
                return;
    
            // drawing all identifier with different color
            if ((e.DrawStage == Alternet.Editor.DrawStage.Before) && (((e.DrawState & Alternet.Editor.DrawState.Text) != 0) && (e.DrawState & Alternet.Editor.DrawState.Selection) == 0))
            {
                Alternet.Syntax.Lexer.LexToken tok = (Alternet.Syntax.Lexer.LexToken)(e.DrawInfo.Style.Data - 1);
                if (tok == Alternet.Syntax.Lexer.LexToken.Identifier)
                    e.Painter.TextColor = System.Drawing.Color.Magenta;
            }
    
            //fill button gradient
            if ((e.DrawStage == Alternet.Editor.DrawStage.Before) && (Alternet.Editor.DrawState.OutlineImage & e.DrawState) != 0)
            {
                var r = e.Rect;
                r.X++;
                r.Y++;
                r.Width--;
                r.Height--;
                e.Painter.FillGradient(r.X, r.Y, r.Width, r.Height, System.Drawing.Color.Blue, System.Drawing.Color.White, e.Rect.Location, new System.Drawing.Point(r.Right, r.Bottom));
                e.Painter.ExcludeClipRect(e.Rect);
            }
        }
    }
    

    Here is how to use a Painter in the Visual Basic code:

    Partial Public Class Form1
        Inherits Form
    
        Private csParser1 As Alternet.Syntax.Parsers.Roslyn.CsParser = New Alternet.Syntax.Parsers.Roslyn.CsParser()
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim syntaxEdit1 = New Alternet.Editor.SyntaxEdit(Me.components)
            AddHandler syntaxEdit1.CustomDraw, New Alternet.Editor.CustomDrawEvent(AddressOf SyntaxEdit1_CustomDraw)
            syntaxEdit1.Outlining.AllowOutlining = True
        End Sub
    
        Private Sub SyntaxEdit1_CustomDraw(ByVal sender As Object, ByVal e As Alternet.Editor.CustomDrawEventArgs)
            If (csParser1.Repository Is Nothing) OrElse csParser1.Repository.Document Is Nothing Then Return
            Dim text = Me.csParser1.Repository.Document.GetTextAsync().Result
            If text Is Nothing Then Return
    
            If (e.DrawStage = Alternet.Editor.DrawStage.Before) AndAlso (((e.DrawState And Alternet.Editor.DrawState.Text) <> 0) AndAlso (e.DrawState And Alternet.Editor.DrawState.Selection) = 0) Then
                Dim tok As Alternet.Syntax.Lexer.LexToken = CType((e.DrawInfo.Style.Data - 1), Alternet.Syntax.Lexer.LexToken)
                If tok = Alternet.Syntax.Lexer.LexToken.Identifier Then e.Painter.TextColor = System.Drawing.Color.Magenta
            End If
    
            If (e.DrawStage = Alternet.Editor.DrawStage.Before) AndAlso (Alternet.Editor.DrawState.OutlineImage And e.DrawState) <> 0 Then
                Dim r = e.Rect
                r.X += 1
                r.Y += 1
                r.Width -= 1
                r.Height -= 1
                e.Painter.FillGradient(r.X, r.Y, r.Width, r.Height, System.Drawing.Color.Blue, System.Drawing.Color.White, e.Rect.Location, New System.Drawing.Point(r.Right, r.Bottom))
                e.Painter.ExcludeClipRect(e.Rect)
            End If
        End Sub
    End Class
    
    In This Article
    Back to top Copyright AlterNET Software Download PDF