Saccharine Dwarf / Dulce Enano
This will be short and sweet: If you want to enter hot keys while in a textbox to quickly enter accented characters (rather than install and set up a special keyboard, or memorize "Ins+01789342" or whatever), use the following code as a starting point to accomplish this:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (this.ActiveControl != null && this.ActiveControl is TextBox)
{
string replacement = "";
TextBox tb = (TextBox)this.ActiveControl;
bool useHTMLCodes = checkBoxUseHTMLCodes.Checked;
if (keyData == (Keys.Control | Keys.A))
{
replacement = useHTMLCodes ? "á" : "á";
}
else if (keyData == (Keys.Control | Keys.Shift | Keys.A))
{
replacement = useHTMLCodes ? "Á" : "Á";
}
if (keyData == (Keys.Control | Keys.E))
{
replacement = useHTMLCodes ? "é" : "é";
}
else if (keyData == (Keys.Control | Keys.Shift | Keys.E))
{
replacement = useHTMLCodes ? "É" : "É";
}
if (keyData == (Keys.Control | Keys.I))
{
replacement = useHTMLCodes ? "í" : "í";
}
else if (keyData == (Keys.Control | Keys.Shift | Keys.I))
{
replacement = useHTMLCodes ? "Í" : "Í";
}
if (keyData == (Keys.Control | Keys.O))
{
replacement = useHTMLCodes ? "ó" : "ó";
}
else if (keyData == (Keys.Control | Keys.Shift | Keys.O))
{
replacement = useHTMLCodes ? "Ó" : "Ó";
}
if (keyData == (Keys.Control | Keys.U))
{
replacement = useHTMLCodes ? "ú" : "ú";
}
else if (keyData == (Keys.Control | Keys.Shift | Keys.U))
{
replacement = useHTMLCodes ? "Ú" : "Ú";
}
if (keyData == (Keys.Control | Keys.Alt | Keys.U))
{
replacement = useHTMLCodes ? "ü" : "ü";
}
else if (keyData == (Keys.Control | Keys.Alt | Keys.Shift | Keys.U))
{
replacement = useHTMLCodes ? "Ü" : "Ü";
}
if (keyData == (Keys.Control | Keys.N))
{
replacement = useHTMLCodes ? "ñ" : "ñ";
}
else if (keyData == (Keys.Control | Keys.Shift | Keys.N))
{
replacement = useHTMLCodes ? "Ñ" : "Ñ";
}
if (keyData == (Keys.Control | Keys.OemQuestion))
{
replacement = useHTMLCodes ? "¿" : "¿";
}
if (keyData == (Keys.Control | Keys.D1))
{
replacement = useHTMLCodes ? "¡" : "¡";
}
if (replacement != "")
{
tb.SelectedText = replacement;
return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
In this case, the code is for Spanish characters (accents, the beginning exclamation mark and question mark, etc.). You can obviously adapt the idea to your needs. I like it because it's an intuitive way to create accented characters (simply mash the "Ctrl" key along with it, such as Ctrl+E for the "é" character; and then to create the capitalized version of the character, sprinkle in the Shift key).
Note: To get this code to compile, you need to add a checkbox to your form named "checkBoxUseHTMLCodes" - or strip that part out of the code, if you don't need it.
Note also that the code above does not display correctly; the HTML codes are shown in both cases/places (it should be the accented or special char in the second instance each time). You need to download the attached file to see the code as it should be seen.
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).
Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.
I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006: http://www.lulu.com/spotlight/blackbirdcraven