Articles in this section
Category / Section

How to implement the strikethrough feature in the WinForms SyntaxEditor (EditControl)?

2 mins read

Strikethrough

The below code illustrates the strikethrough feature to strike through the current line, the selected text and a range of text in the EditControl. This is a useful feature in denoting text that was deleted from the original document or highlighting offending code or unwanted text. The strikethrough color can be varied by varying the arguments in the StrikeThrough method.

C#

private void menuItem1_Click(object sender, System.EventArgs e)
{
   // Strike out the current line
   this.editControl1.StrikeThrough(this.editControl1.CurrentLine, Color.IndianRed);
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
   // Strike out the selected text
   this.editControl1.StrikeThrough(this.editControl1.Selection.Top, this.editControl1.Selection.Bottom, Color.Navy);
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
   int startOffsetValue = 100;
   int endOffsetValue = 240;
   // 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((ILexemParser)this.editControl1.Parser,    startParsePoint, startVirtualPoint.Y, startVirtualPoint.X, true);
   CoordinatePoint endCoordinatePoint = new CoordinatePoint((ILexemParser)this.editControl1.Parser, endParsePoint, endVirtualPoint.Y, endVirtualPoint.X, true);
   // Strike out the text in the specified text range
   this.editControl1.StrikeThrough(startCoordinatePoint, endCoordinatePoint, Color.Brown);
}

 

VB

Private Sub menuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuItem1.Click
   ' Strike out the current line
   Me.editControl1.StrikeThrough(Me.editControl1.CurrentLine, Color.IndianRed)
End Sub 'menuItem1_Click
Private Sub menuItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuItem2.Click
   ' Strike out the selected text
   Me.editControl1.StrikeThrough(Me.editControl1.Selection.Top, Me.editControl1.Selection.Bottom, Color.Navy)
End Sub 'menuItem2_Click
Private Sub menuItem3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuItem3.Click
   Dim startOffsetValue As Integer = 100
   Dim endOffsetValue As Integer = 240
   ' Starting offset converted to virtual point
   Dim startVirtualPoint As System.Drawing.Point =    Me.editControl1.ConvertOffsetToVirtualPosition(startOffsetValue)
   ' Ending offset converted to virtual point
   Dim endVirtualPoint As System.Drawing.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)
   ' Strike out the text in the specified text range
   Me.editControl1.StrikeThrough(startCoordinatePoint, endCoordinatePoint, Color.Aqua)
End Sub 'menuItem3_Click

 

Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/text-visualization#strike-out

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