We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How can I use Autoindent and AutoReplaceTrigger functionalities in Edit control.

 

It is possible to turn on auto-indentation by setting AutoIndentMode property to Smart and by setting the value of Indent attribute of Lexem tag to true for that lexem in the XML configuration file.

To trigger AutoReplaceTrigger when the keyword is indentended, then you have to handle KeyUp event and replace the old text then insert the new one.

C#

this.editControl1.UseAutoreplaceTriggers = true;

this.editControl1.Language.AutoReplaceTriggers.AddRange(new AutoReplaceTrigger[] { new AutoReplaceTrigger("endif", "endIf") });

void editControl1_KeyUp(object sender, KeyEventArgs e)

{

if (((this.editControl1.GetLine(this.editControl1.CurrentLine)).FindLexemByColumn(this.editControl1.CurrentColumn - 1)) != null)

{

foreach (AutoReplaceTrigger trigger in this.editControl1.Language.AutoReplaceTriggers)

{

ILexem lem= this.editControl1.GetLine(this.editControl1.CurrentLine).FindLexemByColumn(this.editControl1.GetCurrentWordColumn());

Console.WriteLine(lem.Text);

// If the current word has to be replaced

if (trigger.From == ((this.editControl1.GetLine(this.editControl1.CurrentLine)).FindLexemByColumn((this.editControl1.GetCurrentWordColumn()))).Text && this.editControl1.AutoIndentGuideline)

{

//Delete the word

this.editControl1.DeleteText(this.editControl1.Parser.GetCoordinatePoint(this.editControl1.CurrentLine, this.editControl1.GetCurrentWordColumn()), this.editControl1.Parser.GetCoordinatePoint(this.editControl1.CurrentLine, (((((this.editControl1.GetLine(this.editControl1.CurrentLine)).FindLexemByColumn(this.editControl1.GetCurrentWordColumn())).Text).Length) + this.editControl1.GetCurrentWordColumn())));

//Insert the word

this.editControl1.InsertText(this.editControl1.CurrentLine, this.editControl1.CurrentColumn, trigger.To);

int start = this.editControl1.CurrentColumn - lem.Text.Length;

CoordinatePoint _EndPoint = this.editControl1.Parser.GetCoordinatePoint(this.editControl1.CurrentLine, start);

CoordinatePoint _StartPoint = this.editControl1.Parser.GetCoordinatePoint(this.editControl1.CurrentLine, start - 1);

this.editControl1.DeleteText(_StartPoint, _EndPoint);

this.editControl1.CurrentColumn = this.editControl1.CurrentColumn + lem.Text.Length;

break;

}

}

}

VB

Me.editControl1.UseAutoreplaceTriggers = True

Me.editControl1.Language.AutoReplaceTriggers.AddRange(New AutoReplaceTrigger() { New AutoReplaceTrigger("endif", "endIf") })

Private Sub editControl1_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs)

If Not ((Me.editControl1.GetLine(Me.editControl1.CurrentLine)).FindLexemByColumn(Me.editControl1.CurrentColumn - 1)) Is Nothing Then

For Each trigger As AutoReplaceTrigger In Me.editControl1.Language.AutoReplaceTriggers

Dim lem As ILexem= Me.editControl1.GetLine(Me.editControl1.CurrentLine).FindLexemByColumn(Me.editControl1.GetCurrentWordColumn())

If trigger.From = ((Me.editControl1.GetLine(Me.editControl1.CurrentLine)).FindLexemByColumn((Me.editControl1.GetCurrentWordColumn()))).Text AndAlso Me.editControl1.AutoIndentGuideline Then

Me.editControl1.DeleteText(Me.editControl1.Parser.GetCoordinatePoint(Me.editControl1.CurrentLine, Me.editControl1.GetCurrentWordColumn()), Me.editControl1.Parser.GetCoordinatePoint(Me.editControl1.CurrentLine, (((((Me.editControl1.GetLine(Me.editControl1.CurrentLine)).FindLexemByColumn(Me.editControl1.GetCurrentWordColumn())).Text).Length) + Me.editControl1.GetCurrentWordColumn())))

''Insert the word

Me.editControl1.InsertText(Me.editControl1.CurrentLine, Me.editControl1.CurrentColumn, trigger.To)

Dim start As Integer = Me.editControl1.CurrentColumn - lem.Text.Length

Dim _EndPoint As CoordinatePoint = Me.editControl1.Parser.GetCoordinatePoint(Me.editControl1.CurrentLine, start)

Dim _StartPoint As CoordinatePoint = Me.editControl1.Parser.GetCoordinatePoint(Me.editControl1.CurrentLine, start - 1)

Me.editControl1.DeleteText(_StartPoint, _EndPoint)

Me.editControl1.CurrentColumn = Me.editControl1.CurrentColumn + lem.Text.Length

Exit For

End If

Next trigger

End If

End Sub

Please refer to the attached sample from the following page

http://websamples.syncfusion.com/samples/Edit/Autoindent and AutoReplaceTrigger/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
396 04/30/2011 07/10/2014 Windows Forms EditControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.