SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Highlighting a selection based on position

Last post 01-07-2010 4:54 PM by DanielGrunwald. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-06-2010 10:17 PM

    Highlighting a selection based on position

     Hello,

    Is there a way to Highlight text based on position ie line # 3  start(15) end(25) or something similar? Thanks for any help in advanced

     

    -Ryan

  • 01-06-2010 11:22 PM In reply to

    Re: Highlighting a selection based on position

    I'm assuming you are using the old text editor and not the new .NET 4.0 one (AvalonEdit).

    You can get line information from the IDocument.GetLineSegment method.

    The LineSegment will give you an offset and length which you can then use to create a TextMarker with a particular color.

    Then add the TextMarker to the IDocument.MarkerStrategy using the AddMarker method.

    There are a few examples in the SharpDevelop source code to do this (e.g CodeCoverageHighlighter, CodeCoverageTextMarker).

  • 01-07-2010 4:00 PM In reply to

    Re: Highlighting a selection based on position

     Actually I am using the icsharp.avalonedit .net 3.5 wpf sample as a starting place. Any thoughts on that  architecture

  • 01-07-2010 4:54 PM In reply to

    Re: Highlighting a selection based on position

    Text markers are not built into AvalonEdit, but you can implement them easily yourself.

    To change the properties of the text being rendered (e.g. foreground color), use a VisualLineTransformer (e.g. DocumentColorizingTransformer).

    To render a background, use the IBackgroundRenderer interface. The BackgroundGeometryBuilder class will help you finding the position for drawing.

    Take a look at the rendering "missing chapter" from my article: http://danielgrunwald.de/coding/AvalonEdit/rendering.php

    I've already copied most of that information into the AvalonEdit help file, but you'll have to compile it yourself using Sandcastle - the help file download on CodeProject is an old version.

Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.