Introduction
This article describes a simple approach to implementing special character use in a C# based text editor. If your OS is configured for English and you'd like to leave it like that, and if you have not quite memorized all of the key code values required to insert all of the special characters you might use in writing; or if you work from a laptop without a number pad, then this article will offer an alternative approach and may be of interest.

Figure 1: Test Application in Use

Figure 2: Character Selection from a Context Menu
Rather than remembering to lock the number pad and to type things like ALT+0192 or ALT+134, I found it easier to provide an interface in the form of a context menu. To handle case differences, I set it up to insert upper case versions of the characters if I use Shift+F1 to open the menu or lower case versions of the characters if I open the menu with F1 without the shift key. The lower case version is also available using a right click. You won't win any speed typing awards going this route but it is less error prone than keying the codes and will work for you even if you don't have a number pad on your keyboard as is the case with my laptop.
I built the example on top of a fleshed out rich text editor that is also described and available on this site.
Getting Started
The solution contains a developed word processor built around the rich text box control; that much of the code will not be described herein but a description is available on this site in an earlier article. This article will only address that part of the code used to handle the context menu to do the character inserts.

Figure 3: Solution Explorer with the Project Visible
All of the code discussed in this article is contained in frmMain.cs. As a delta from the original editor, the main form was modified by the addition of an insert menu which contains most of the French Accent Marks and through the addition of a context menu with the same characters made available by the new insert menu. A similar approach could be used to allow the user to insert other special characters such as mathematical equation symbols or any other special character that might be of interest to the user.
Code: Main Form (frmMain.cs)
This class provides all of the functionality used in this example to allow the user to insert special characters. The bulk of the code in this class will not be discussed; only those parts that pertain to the placement of special characters into the document.
The first part of the code to depart from the original version of the C# based word processor project is the declarations region of the main form. In this section, two new variables are declared, the first is a point used to maintain awareness as to the physical location of the mouse (which is later used to decide where to show the context menu) and the second is a string variable entitled "mode" which is used to maintain awareness as to whether or not to use upper case or lower case when inserting the character.
#region "Declaration"
private string currentFile;
private int checkPrint;
private Point pLocation;
private string mode;
#endregion
The next new part of the application is used to insert the French accent marks into the active document. The following event handlers and these are the handlers for the new insert menu. All work the same and when called, each will insert the requested accent mark into the document at the position of the cursor.
#region French Accent Marks
/// <summary>
/// Accent Grave - à
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void àToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "à";
}
/// <summary>
/// Accent Grave - è
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void èToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "è";
}
/// <summary>
/// Accent Grave - ù
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ùToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "ù";
}
/// <summary>
/// Accent Aigu - é
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void éToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "é";
}
/// <summary>
/// Accent circonflexe - â
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void âToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "â";
}
/// <summary>
/// Accent circonflexe - ê
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void êToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "ê";
}
/// <summary>
/// Accent circonflexe - î
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void îToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "î";
}
/// <summary>
/// Accent circonflexe - ô
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ôToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "ô";
}
/// <summary>
/// Accent circonflexe - û
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ûToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "û";
}
/// <summary>
/// Accent tréma - ë
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ëToolStripMenuItem_Click(object sender, EventArgs e)
{
rtbDoc.SelectedText = "ë";
}

Join the conversation! Your thoughts help the community grow.