Knowledgebase Home Page  >  RapidSpell Desktop .NET  >  3rd Party Ctrls
Search the Knowledge Base
How can I use RapidSpellDialog with EditControl from Syncfusion?
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=111&catId=61

Options

Print this page
Email this to a friend
To do this, as with most 3rd party text controls, we create an 'adapter' class that sits between the RapidSpellDialog and the text editor control - this class implements ISpellCheckableTextComponent.
 
 
The adapter class is below, it is used like this:
 
 
Adapter usage (in the form with the RapidSpellDialog control)
 
C#
 

adapter = new SyncfusionEditControlAdapter(this.editControl1);    //instantiate this once for the form

...

this.rapidSpellDialog1.ThirdPartyTextComponentToCheck = adapter;

this.rapidSpellDialog1.Check();

 
VB.NET

adapter = New SyncfusionEditControlAdapter(Me.editControl1)    'instantiate this once for the form

...

rapidSpellDialog1.ThirdPartyTextComponentToCheck = adapter

rapidSpellDialog1.Check()

 

 

 

The adapter class

C#

using System;

 

/// <summary>

/// Summary description for SyncfusionEditControlAdapter.

/// </summary>

public class SyncfusionEditControlAdapter : Keyoti.RapidSpell.ISpellCheckableTextComponent

{

Syncfusion.Windows.Forms.Edit.EditControl tb;

public SyncfusionEditControlAdapter(Syncfusion.Windows.Forms.Edit.EditControl tb)

{

this.tb = tb;

this.tb.GotFocus += new EventHandler(this.OnGotFocus);

}

~SyncfusionEditControlAdapter()

{

if(tb!=null)

tb.GotFocus -= new EventHandler(this.OnGotFocus);

}

public event EventHandler GotFocus;

void OnGotFocus(object s, EventArgs e)

{

if(GotFocus!=null) GotFocus(this,e);

}

public void ScrollToCaret()

{

//not implemented

}

public bool HideSelection

{

get{return false;//not implemented

}

set{//not implemented

}

}

public string SelectedText

{

get{return tb.SelectedText;}

set{

tb.SelectedText=value;

}

}

public int SelectionStart

{

get{

return LineAndCharToAbsCharIndex(tb.CurrentColumn, tb.CurrentLine);

}

set{

int[] selParams = AbsCharIndexToLineAndChar(value);

tb.SetSelection(selParams[1], selParams[0], selParams[1], selParams[0]);

tb.CurrentLine = selParams[0];

tb.CurrentColumn = selParams[1];

}

}

public int LineAndCharToAbsCharIndex(int column, int line)

{

string[] lines = tb.Lines;

int totLen=0;

int newlineCharLen=1;

for(int l=0; l<lines.Length && l<(line-1); l++)

{

totLen += lines[l].Length + newlineCharLen;;

}

return totLen += column-1;

}

//[0] = line

//[1] = col

public int[] AbsCharIndexToLineAndChar(int absoluteOffset)

{

string[] lines = tb.Lines;

int totLen=0;

int targetLine=0;

int newlineCharLen=1;

for(int l=0; l<lines.Length; l++){

if(lines[l].Length + totLen + newlineCharLen <= absoluteOffset)

{

totLen += lines[l].Length + newlineCharLen;

}

else

{

targetLine=l;

break;

}

}

return new int[]{targetLine+1, (absoluteOffset - totLen)+1};

}

public int SelectionLength

{

get{

if(tb.Selection==null) return 0;

else

{

Syncfusion.Windows.Forms.Edit.Utils.ITextRange r = tb.Selection;

Syncfusion.Windows.Forms.Edit.Utils.CoordinatePoint end = r.End;

return LineAndCharToAbsCharIndex(end.VirtualColumn, end.VirtualLine) - SelectionStart;

}

}

set{

int[] end = AbsCharIndexToLineAndChar(SelectionStart + value);

tb.SetSelection(tb.CurrentColumn, tb.CurrentLine, end[1], end[0]);

}

}

public string Text

{

get{return tb.Text;}

set{tb.Text=value;}

}

}

 

 

 

VB.NET

Imports System
 

    _
   '/ <summary>
   '/ Summary description for SyncfusionEditControlAdapter.
   '/ </summary>

Public Class SyncfusionEditControlAdapter

Implements Keyoti.RapidSpell.ISpellCheckableTextComponent

Private tb As TextBox

Public Event GotFocus As EventHandler Implements Keyoti.RapidSpell.ISpellCheckableTextComponent.GotFocus

Public Sub New(ByVal tb As TextBox)

Me.tb = tb

AddHandler Me.tb.Enter, New EventHandler(AddressOf Me.OnGotFocus)

End Sub 'New

 

Protected Overloads Overrides Sub Finalize()

 

If Not (tb Is Nothing) Then

RemoveHandler Me.tb.Enter, New EventHandler(AddressOf Me.OnGotFocus)

End If

MyBase.Finalize()

End Sub 'Finalize

 

 

 

Sub OnGotFocus(ByVal s As Object, ByVal e As EventArgs)

RaiseEvent GotFocus(Me, e)

End Sub 'OnGotFocus

 

Public Overridable Overloads Sub ScrollToCaret() Implements Keyoti.RapidSpell.ISpellCheckableTextComponent.ScrollToCaret

End Sub 'ScrollToCaret

 

 

Public Property HideSelection() As Boolean Implements Keyoti.RapidSpell.ISpellCheckableTextComponent.HideSelection

 

Get

Return False 'not implemented

End Get

Set(ByVal Value As Boolean) 'not implemented

End Set

End Property

 

 

Public Property SelectedText() As String Implements Keyoti.RapidSpell.ISpellCheckableTextComponent.SelectedText

 

Get

Return tb.SelectedText

End Get

Set(ByVal Value As String)

tb.SelectedText = Value

End Set

End Property

Public Property SelectionStart() As Integer Implements Keyoti.RapidSpell.ISpellCheckableTextComponent.SelectionStart


         
         
         Get
            Return LineAndCharToAbsCharIndex(tb.CurrentColumn, tb.CurrentLine)
         End Get
        
         Set
            Dim selParams As Integer() = AbsCharIndexToLineAndChar(value)
            tb.SetSelection(selParams(1), selParams(0), selParams(1), selParams(0))
            tb.CurrentLine = selParams(0)
            tb.CurrentColumn = selParams(1)
         End Set
      End Property
      
     
      Public Function LineAndCharToAbsCharIndex(column As Integer, line As Integer) As Integer
         Dim lines As String() = tb.Lines
         Dim totLen As Integer = 0
         Dim newlineCharLen As Integer = 1
         Dim l As Integer
         For l = 0 To
            totLen += lines(l).Length + newlineCharLen
         Next l
         Return totLen += column - 1 'ToDo: Unsupported feature: assignment within expression
      End Function 'LineAndCharToAbsCharIndex
     
     
      '[0] = line
      '[1] = col
      Public Function AbsCharIndexToLineAndChar(absoluteOffset As Integer) As Integer()
         Dim lines As String() = tb.Lines
         Dim totLen As Integer = 0
         Dim targetLine As Integer = 0
         Dim newlineCharLen As Integer = 1
         Dim l As Integer
         For l = 0 To lines.Length - 1
            If lines(l).Length + totLen + newlineCharLen <= absoluteOffset Then
               totLen += lines(l).Length + newlineCharLen
           
            Else
               targetLine = l
               Exit For
            End If
         Next l
         Return New Integer() {targetLine + 1, absoluteOffset - totLen + 1}
      End Function 'AbsCharIndexToLineAndChar
     
     
      Public Property SelectionLength() As Integer Implements Keyoti.RapidSpell.ISpellCheckableTextComponent.SelectionLength


         Get
           
            If tb.Selection Is Nothing Then
               Return 0
            Else
               Dim r As Syncfusion.Windows.Forms.Edit.Utils.ITextRange = tb.Selection
               Dim [end] As Syncfusion.Windows.Forms.Edit.Utils.CoordinatePoint = r.End
               Return LineAndCharToAbsCharIndex([end].VirtualColumn, [end].VirtualLine) - SelectionStart
            End If
         End Get
        
         Set
           
            Dim [end] As Integer() = AbsCharIndexToLineAndChar((SelectionStart + value))
            tb.SetSelection(tb.CurrentColumn, tb.CurrentLine, [end](1), [end](0))
         End Set
      End Property 
     

Public Property [Text]() As String Implements Keyoti.RapidSpell.ISpellCheckableTextComponent.Text

Get

Return tb.Text

End Get

Set(ByVal Value As String)

tb.Text = Value

End Set

End Property

End Class

 


Related Questions:

Attachments:

No attachments were found.