Knowledgebase Home Page  >  RapidSpell Desktop .NET  >  3rd Party Ctrls
Search the Knowledge Base
When using Headers/Footers with TX TextControl the dialog spell checker corrects the main body instead of the header. (C#)
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=75&catId=61

Options

Print this page
Email this to a friend
 
 
To correct this behavior you must use a replacement TXTextControlAdapter class (below).
 
Use this class similarly to built-in TXTextControlAdapter in the main form, eg;
 

private TXTextControlAdapter2 txTextControlAdapter1;

...

this.txTextControlAdapter1 = new Simple.TXTextControlAdapter2();

this.txTextControlAdapter1.TextControl = this.TextControl1;

this.rapidSpellDialog1.ThirdPartyTextComponentToCheck = this.txTextControlAdapter1;

 
The only additional thing that needs to be done is that you must set

txTextControlAdapter1.IgnoreHeaderFooterDeactivationEvents = true;

when starting the spell checker, and false when finished, eg;
 

private void menuItem2_Click(object sender, System.EventArgs e)

{

this.txTextControlAdapter1.IgnoreHeaderFooterDeactivationEvents = true;

this.rapidSpellDialog1.Check();

}

and an event handler

private void rapidSpellDialog1_SpellCheckFinished(object sender, Keyoti.RapidSpell.Event.SpellCheckEventArgs e)

{

this.txTextControlAdapter1.IgnoreHeaderFooterDeactivationEvents = false;

}

 
The class
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 

using Keyoti.RapidSpell;

using System;

using System.Windows.Forms;

using System.Drawing;

using TXTextControl;

using System.ComponentModel;

using Keyoti.RapidSpell.FrameWorkSpecific;

 

namespace Simple

{

///<summary>Wraps TXTextControl with an IAYTTextBox interface for As You Type checking and ISpellCheckableTextComponent interface for Dialog checking.</summary>

///<remarks>This allows developers to use RapidSpellAsYouType with TXTextControl from The Imaging Source.

///<p><b>Note:</b>Direct use of this class's members is not recommended and the interface is subject to change.</p></remarks>

///<example><code>

/// //-C#

/// //Instantiate RapidSpellAsYouType

/// RapidSpellAsYouType rapidSpellAsYouType = new RapidSpellAsYouType();

/// //Set the TextComponent property, where TextControl1 is TXTextControl

/// rapidSpellAsYouType.TextComponent = new Keyoti.RapidSpell.TXTextControlAdapter( TextControl1 );

///</code></example>

///<example><code>

/// ‘-VB.NET

/// ‘Instantiate RapidSpellAsYouType

/// Dim rsayt As RapidSpellAsYouType = New RapidSpellAsYouType()

/// ‘Set the TextComponent property, where TextControl1 is TXTextControl

/// Me.rsayt.TextComponent = New TXTextControlAdapter(Me.TextControl1)

///</code></example>

public class TXTextControlAdapter2 : Component, ISpellCheckableTextComponent

{

TXTextControl.TextControl txc;

///<summary>Create a new TXTextControl wrapper, specify TextControl before spell checking.</summary>

public TXTextControlAdapter2(){}

///<summary>Create a new TXTextControl wrapper.</summary>

public TXTextControlAdapter2(TXTextControl.TextControl txc)

{

if(txc!=null)

setTextControl(txc);

}

bool inHeaderFooter = false;

TXTextControl.HeaderFooter currentHeaderFooter;

private void txc_HeaderFooterActivated(object sender, TXTextControl.HeaderFooterEventArgs e)

{

inHeaderFooter = true;

currentHeaderFooter = e.HeaderFooter;

}

private void txc_HeaderFooterDeactivated(object sender, TXTextControl.HeaderFooterEventArgs e)

{

if(!IgnoreHeaderFooterDeactivationEvents)

inHeaderFooter = false;

}

public bool IgnoreHeaderFooterDeactivationEvents = false;

void OnTBDisposed(object s, EventArgs e)

{

if(txc!=null)

{

txc.Changed -= new EventHandler( OnTextChanged );

txc.KeyDown -= new KeyEventHandler( OnKeyDown );

txc.KeyUp -= new KeyEventHandler( OnKeyUp );

txc.MouseDown -= new MouseEventHandler( OnMousePressed );

txc.MouseUp -= new MouseEventHandler( OnMouseReleased );

txc.GotFocus-= new EventHandler( OnEnter);

txc.Leave-= new EventHandler( OnLeave);

txc.Disposed -= new EventHandler( OnTBDisposed );

txc.HeaderFooterActivated -= new HeaderFooterEventHandler(txc_HeaderFooterActivated);

txc.HeaderFooterDeactivated -= new HeaderFooterEventHandler(txc_HeaderFooterDeactivated);

}

}

void setTextControl(TXTextControl.TextControl txc)

{

this.txc = txc;

txc.Changed += new EventHandler( OnTextChanged );

txc.KeyDown += new KeyEventHandler( OnKeyDown );

txc.KeyUp += new KeyEventHandler( OnKeyUp );

txc.MouseDown += new MouseEventHandler( OnMousePressed );

txc.MouseUp += new MouseEventHandler( OnMouseReleased );

txc.GotFocus+= new EventHandler( OnEnter);

txc.Disposed += new EventHandler( OnTBDisposed );

txc.Leave+= new EventHandler( OnLeave);

txc.HeaderFooterActivated += new HeaderFooterEventHandler(txc_HeaderFooterActivated);

txc.HeaderFooterDeactivated += new HeaderFooterEventHandler(txc_HeaderFooterDeactivated);

}

 

///<summary>The TXTextControl to be spell checked.</summary>

[Description("The TXTextControl to be spell checked."),Category("Behavior")]

public TextControl TextControl

{

get { return txc; }

set

{

if(value!=null) setTextControl(value);

else txc = null;

}

}

///<summary>Gets or sets a value indicating whether the selected text in the text box control remains highlighted when the control loses focus.</summary>

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public bool HideSelection

{

get

{

if(txc==null) throw new InvalidOperationException("TextControl property not set to (non-null) instance (set TextControl property before starting spell check).");

return txc.HideSelection;

}

set

{

if(txc==null) throw new InvalidOperationException("TextControl property not set to (non-null) instance (set TextControl property before starting spell check).");

txc.HideSelection = value;}

}

///<summary>Scrolls to caret.</summary>

[Browsable(false)]

public void ScrollToCaret()

{

 

 

}

///<summary>Finalizer, removes event listeners</summary>

~TXTextControlAdapter2()

{

if(txc!=null)

{

txc.Changed -= new EventHandler( OnTextChanged );

txc.KeyDown -= new KeyEventHandler( OnKeyDown );

txc.KeyUp -= new KeyEventHandler( OnKeyUp );

txc.MouseDown -= new MouseEventHandler( OnMousePressed );

txc.MouseUp -= new MouseEventHandler( OnMouseReleased );

txc.GotFocus-= new EventHandler( OnEnter);

txc.Disposed -= new EventHandler( OnTBDisposed );

txc.Leave-= new EventHandler( OnLeave);

txc.HeaderFooterActivated -= new HeaderFooterEventHandler(txc_HeaderFooterActivated);

txc.HeaderFooterDeactivated -= new HeaderFooterEventHandler(txc_HeaderFooterDeactivated);

}

}

 

 

void OnTextChanged(object sender, EventArgs e)

{

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

}

void OnKeyDown(object sender, KeyEventArgs e)

{

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

}

void OnKeyUp(object sender, KeyEventArgs e)

{

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

}

void OnMousePressed(object sender, MouseEventArgs e)

{

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

}

void OnMouseReleased(object sender, MouseEventArgs e)

{

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

}

void OnEnter(object sender, EventArgs e)

{

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

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

}

void OnLeave(object sender, EventArgs e)

{

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

}

 

///<summary>Occurs when the Text property value changes.</summary>

public event EventHandler TextChanged;

///<summary>Occurs when a key is released while the control has focus.</summary>

public event KeyEventHandler KeyUp;

///<summary>Occurs when a key is pressed while the control has focus.</summary>

public event KeyEventHandler KeyDown;

///<summary>Occurs when the mouse pointer is over the control and a mouse button is pressed.</summary>

public event MouseEventHandler MouseDown;

///<summary>Occurs when the control receives focus.</summary>

public event EventHandler Enter;

///<summary>Occurs when the control loses focus.</summary>

public event EventHandler Leave;

///<summary>Occurs when the control receives focus.</summary>

public event EventHandler GotFocus;

///<summary>Occurs when the mouse is released on the text box.</summary>

public event MouseEventHandler MouseUp;

 

 

///<summary>Gets or sets the starting point of text selected in the text box.</summary>

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public int SelectionStart

{

get

{

//return selection according to whether in header or main body

if(inHeaderFooter)

{

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

else

return currentHeaderFooter.Selection.Start;

} else {

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

else

return txc.Selection.Start;

}

}

set

{

if(inHeaderFooter)

{

if(currentHeaderFooter.Selection!=null)currentHeaderFooter.Selection.Start = value;

// currentHeaderFooter.InputPosition =new TXTextControl.InputPosition(value);

}

else

{

if(txc.Selection!=null)txc.Selection.Start = value;

txc.InputPosition =new TXTextControl.InputPosition(value);

}

}

}

///<summary>Gets or sets the number of characters selected in the text box.</summary>

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public int SelectionLength

{

get{

if(inHeaderFooter)

return currentHeaderFooter.Selection.Length;

else

return txc.Selection.Length;

}

set

{

if(inHeaderFooter)

{

if(currentHeaderFooter.Selection!=null)

currentHeaderFooter.Selection.Length = value;

}

else

if(txc.Selection!=null)

txc.Select(SelectionStart, value);

}

}

///<summary>Gets or sets a value indicating the currently selected text in the control.</summary>

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public string SelectedText

{

get{

if(inHeaderFooter)

return currentHeaderFooter.Selection.Text;

else

return txc.Selection.Text;

}

set{

if(inHeaderFooter)

currentHeaderFooter.Selection.Text = value;

else

txc.Selection.Text = value;

}

}

 

 

 

//http://www.theimagingsourceforums.com/showthread.php?s=10028ecaaccad7f706f95bf5acec3518&threadid=315105&highlight=doubledinputposition

///<summary>Gets or sets the current text in the text box.</summary>

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public string Text

{

get

{

if(inHeaderFooter)

return currentHeaderFooter.Selection.Text.Replace("\n", String.Empty);

else

return

//remove special chars that shouldn't count as text positions

txc.Text.Replace("\n", String.Empty);

}

set{

if(inHeaderFooter)

currentHeaderFooter.Selection.Text=value;

else

txc.Text=value;

}

}

 

}

}


Related Questions:

Attachments:

No attachments were found.