AutoCorrectEventArgs.AutoCorrectInfo Property
Gets or sets the AutoCorrectInfo object that provides methods to analyze input text and contains a replacement object.
Namespace: DevExpress.XtraRichEdit
Assembly: DevExpress.RichEdit.v24.2.Core.dll
NuGet Package: DevExpress.RichEdit.Core
Declaration
Property Value
Type | Description |
---|---|
AutoCorrectInfo | An AutoCorrectInfo object. |
Remarks
The AutoCorrectInfo is the main source of information used in handling the AutoCorrect event.
The following code sample shows how to handle the RichEditControl.AutoCorrect event to replace the typed $ symbol with a picture of a dollar, and substitute the text enclosed in percent symbols with custom content.
Use the AutoCorrectEventArgs.AutoCorrectInfo
property to obtain the document text, then call the AutoCorrectInfo.DecrementStartPosition method to expand its left boundary until a special symbol or a word separator symbol is found. Use the AutoCorrectInfo.ReplaceWith property to pass a replacement object (a string or an image) to the document if a resulting string meets certain conditions, such as whether it is a dollar sign or a %date% string.
private void richEditControl1_AutoCorrect(object sender, DevExpress.XtraRichEdit.AutoCorrectEventArgs e)
{
AutoCorrectInfo info = e.AutoCorrectInfo;
e.AutoCorrectInfo = null;
if (info.Text.Length <= 0)
return;
for (; ; ) {
if (!info.DecrementStartPosition())
return;
if (IsSeparator(info.Text[0]))
return;
if (info.Text[0] == '$') {
info.ReplaceWith = CreateImageFromResx("dollar_pic.png");
e.AutoCorrectInfo = info;
return;
}
if (info.Text[0] == '%') {
string replaceString = CalculateFunction(info.Text);
if (!String.IsNullOrEmpty(replaceString)) {
info.ReplaceWith = replaceString;
e.AutoCorrectInfo = info;
}
return;
}
}
}