using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Repository; using DevExpress.XtraEditors.Registrator; namespace DevExpress_Grid { /// /// Paints the AYT Text Box when not in edit mode - this code draws the red "e" in the corner of the cell. /// public class AYTTextEditPainter:DevExpress.XtraEditors.Drawing.TextEditPainter { protected override void DrawString(DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs info, Rectangle bounds, string text, DevExpress.Utils.AppearanceObject appearance) { if(RepositoryItemAYTTextEdit.RapidSpell!=null) { //use the core spell checker from the as you type object Keyoti.RapidSpell.RapidSpellChecker rsc = RepositoryItemAYTTextEdit.RapidSpell.RapidSpellChecker; rsc.ShareDictionary=true; rsc.WarnDuplicates = false; //check the text for errors rsc.Check(text); if(rsc.NextBadWord()!=null)//if errors are present then draw a red 'e' in the corner { info.Graphics.DrawString("e", new Font("Arial", 7), System.Drawing.Brushes.Red, new PointF(info.Bounds.Right-7,info.Bounds.Top)); } } base.DrawString(info, bounds, text, appearance); } } /// /// As You Type TextEdit repository item /// [UserRepositoryItem("Register")] public class RepositoryItemAYTTextEdit : DevExpress.XtraEditors.Repository.RepositoryItemTextEdit { /// /// Shared instance of the spell checker /// public static Keyoti.RapidSpell.RapidSpellAsYouType RapidSpell; /// /// Needs to be called in Form .ctor /// public static void InitRapidSpellAsYouType() { RepositoryItemAYTTextEdit.RapidSpell = new Keyoti.RapidSpell.RapidSpellAsYouType(); RepositoryItemAYTTextEdit.RapidSpell.UserDictionaryFile = "user-dic.txt"; RepositoryItemAYTTextEdit.RapidSpell.IncludeUserDictionaryInSuggestions = true; RepositoryItemAYTTextEdit.RapidSpell.ShowSuggestionsWhenTextIsSelected=true; } internal const string EditorName = "AYTTextEdit"; public static void Register() { EditorRegistrationInfo.Default.Editors.Add( new EditorClassInfo(EditorName, typeof(AYTTextEdit), typeof(RepositoryItemAYTTextEdit), typeof(DevExpress.XtraEditors.ViewInfo.TextEditViewInfo), new AYTTextEditPainter(),//uncomment for regular painter new DevExpress.XtraEditors.Drawing.TextEditPainter(), true, null)); } public override string EditorTypeName { get { return EditorName; } } static RepositoryItemAYTTextEdit() { Register(); } } /// /// As You Type TextEdit /// public class AYTTextEdit : DevExpress.XtraEditors.TextEdit { static AYTTextEdit() { RepositoryItemAYTTextEdit.Register(); } public override string EditorTypeName { get { return RepositoryItemAYTTextEdit.EditorName; } } public new RepositoryItemAYTTextEdit Properties { get { return base.Properties as RepositoryItemAYTTextEdit; } } /// /// The inner text box /// Keyoti.RapidSpell.DevExpressAdapter.AYTTextBoxMaskBox aytBox; protected override TextBoxMaskBox CreateMaskBoxInstance() { //create a new instance of the textbox and assign it to the spell checker Keyoti.RapidSpell.RapidSpellAsYouType rsayt; rsayt = RepositoryItemAYTTextEdit.RapidSpell; aytBox = new Keyoti.RapidSpell.DevExpressAdapter.AYTTextBoxMaskBox(this); rsayt.RapidSpellChecker.ShareDictionary = true; rsayt.TextComponent = aytBox; aytBox.UnderlineYOffset = 0; //use single underlines because not enough room for wavy rsayt.UnderlineStyle = Keyoti.RapidSpell.UnderlineStyle.Single; return aytBox; } } }