Articles in this section
Category / Section

How to convert offset values into text range in the WinForms SyntaxEditor (EditControl)?

1 min read

Convert offset values into text range

In other words, this article explains how to get the associated CoordinatePoint values from text offset values. You would have to convert offset values into VirtualPoints and then VirtualPoints to ParsePoints before converting them to CoordinatePoints. Please refer to the code snippets below that illustrate this.

C#

// Starting offset converted to virtual point
Point startVirtualPoint = this.editControl1.ConvertOffsetToVirtualPosition(startOffsetValue);
// Ending offset converted to virtual point
Point endVirtualPoint = this.editControl1.ConvertOffsetToVirtualPosition(endOffsetValue);
// Converting the VirtualPoints to ParsePoints
ParsePoint startParsePoint = new ParsePoint(startVirtualPoint.Y, startVirtualPoint.X, 0);
ParsePoint endParsePoint = new ParsePoint(endVirtualPoint.Y, endVirtualPoint.X, 0);
// Creating the associated CoordinatePoints that indicate the text range
CoordinatePoint startCoordinatePoint = new CoordinatePoint(this.editControl1.Parser as ILexemParser, startParsePoint, startVirtualPoint.Y, startVirtualPoint.X, true);
CoordinatePoint endCoordinatePoint = new CoordinatePoint(this.editControl1.Parser as ILexemParser, endParsePoint, endVirtualPoint.Y, endVirtualPoint.X, true);

 

VB

' Starting offset converted to virtual point
Dim startVirtualPoint As Point = Me.editControl1.ConvertOffsetToVirtualPosition(startOffsetValue)
' Ending offset converted to virtual point
Dim endVirtualPoint As Point = Me.editControl1.ConvertOffsetToVirtualPosition(endOffsetValue)
' Converting the VirtualPoints to ParsePoints
Dim startParsePoint As New ParsePoint(startVirtualPoint.Y, startVirtualPoint.X, 0)
Dim endParsePoint As New ParsePoint(endVirtualPoint.Y, endVirtualPoint.X, 0)
' Creating the associated CoordinatePoints that indicate the text range
Dim startCoordinatePoint As New CoordinatePoint(CType(Me.editControl1.Parser, ILexemParser), startParsePoint, startVirtualPoint.Y, startVirtualPoint.X, True)
Dim endCoordinatePoint As New CoordinatePoint(CType(Me.editControl1.Parser, ILexemParser), endParsePoint, endVirtualPoint.Y, endVirtualPoint.X, True)

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied