How to Activate Spellcheck in C# Windows Forms
In this article
To activate spellcheck in a C# Windows Forms application, you do not get a built-in spellchecker like the one in Word or in a browser. Windows Forms text controls (TextBox, RichTextBox) have no spellcheck property. The practical way to add it is to use the Windows spellchecking API through the RichTextBox control's built-in support, or to integrate a third-party spellcheck library. The shortest working route is to switch your input control to a RichTextBox, enable its spellcheck through the Windows text services framework, and handle the menu that Windows shows for misspelled words. This guide walks through that approach step by step, then covers the common library alternative and what to do when it does not behave.
What You'll Need
- Visual Studio with a Windows Forms project targeting .NET Framework 4.6.2 or later, or .NET (Core/5+) with Windows Forms support.
- A form with a RichTextBox control (TextBox does not support the Windows spellcheck integration).
- Windows 10 or Windows 11 with the language pack for the language you want to check installed, because the spellchecker uses the Windows language and spellchecking settings.
- Optional: a third-party spellcheck library if you need inline squiggles inside a plain TextBox or need to control the dictionary yourself.
Step-by-Step
- Add a RichTextBox to your form. Open your form in the designer, drag a RichTextBox from the toolbox onto it, and give it a name such as
richTextBox1. If you already use a TextBox, replace it or add the RichTextBox alongside it. The Windows spellcheck integration is exposed through the RichTextBox control, not the plain TextBox. - Set the language for the control. In the designer, select the RichTextBox, open the Properties window, and find the
Languageproperty under the Behavior section. Set it to the language you want checked, for exampleEnglish (United States). If you set this in code, use theLanguageproperty with a culture such asnew System.Globalization.CultureInfo("en-US"). The spellchecker follows this language setting. - Enable the Windows spellcheck integration. The RichTextBox exposes spellchecking through the Windows text services framework. In code, after the control is created, set the spellcheck option using the control's text services. The reliable way is to send the
EM_SETLANGOPTIONSmessage to the control's handle with the spellcheck flag enabled, or to use theRichTextBoxmethod that turns on the built-in proofing. In practice, many projects call the Windows APISendMessagewithEM_SETLANGOPTIONSand theIMF_SPELLCHECKINGflag. Add the following pattern in your form's constructor afterInitializeComponent():
The code below uses P/Invoke to send the message. Place the DllImport declaration at class level and call the method after the handle is created:
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
private const int EM_SETLANGOPTIONS = 0x0450;
private const int IMF_SPELLCHECKING = 0x00000800;
// In the form constructor after InitializeComponent():
SendMessage(richTextBox1.Handle, EM_SETLANGOPTIONS, IntPtr.Zero, (IntPtr)IMF_SPELLCHECKING);
- Make sure the handle exists. The call above needs the control's window handle. If you call it in the constructor before the form is shown, the handle may not be created yet. Either call it in the form's
Loadevent or callrichTextBox1.CreateControl()first. A safe place is theLoadevent handler. - Run the application and type a misspelled word. Press F5, type something like "teh" into the RichTextBox, and pause. Windows should underline the word with a red squiggle and show a context menu with suggestions when you right-click it. If the squiggle appears, spellcheck is active.
- Handle the context menu if you need custom behavior. The suggestions menu is provided by Windows, not by your code. If you want to add your own items, handle the
MouseUpevent and show a ContextMenuStrip, but be aware that replacing the default menu removes the Windows suggestions. For most applications, leave the default menu in place. - Test with a second language if needed. Change the
Languageproperty to another installed language and confirm the squiggles follow. If the language is not installed in Windows, spellcheck will not work for it; install the language pack through Windows Settings first. - Consider a library for plain TextBox controls. If you must keep a TextBox, the Windows integration will not work there. Use a maintained spellcheck library from NuGet that provides a TextBox-compatible checker, or switch the control to a RichTextBox. Libraries typically require you to supply a dictionary file and to handle the word-checking event yourself.
Common Mistakes
- Using a TextBox instead of a RichTextBox. The Windows spellcheck integration is not exposed on the plain TextBox. This is the most common reason the squiggles never appear.
- Calling the API before the handle exists. Sending
EM_SETLANGOPTIONSin the constructor before the control is created silently does nothing. Move the call to theLoadevent or callCreateControl()first. - Forgetting the language pack. If the language set on the control is not installed in Windows, spellcheck does nothing. Check Windows Settings > Time & Language > Language & region.
- Assuming the squiggle is a control property. There is no
SpellCheckproperty on RichTextBox. The feature comes from the Windows text services framework, which is why the API call is needed. - Replacing the default context menu. If you assign your own ContextMenuStrip, the Windows suggestions menu is replaced and users lose the correction options.
Tips
- Set the
Languageproperty explicitly rather than relying on the system default, so the behavior is predictable across machines. - Test on a clean Windows install or a machine without extra language packs, because spellcheck depends on the operating system, not on your project.
- If you need spellcheck in a multiline editor with formatting, RichTextBox is the natural fit; it already supports the Windows proofing features.
- Keep the P/Invoke call in one helper method so you can reuse it for multiple RichTextBox controls on the same form.
- Remember that labels in Windows menus and settings can differ slightly by Windows version and region; the control properties in Visual Studio are stable, but the Windows language settings wording may vary.
Troubleshooting
If no squiggles appear, first confirm the control is a RichTextBox and that the Language property is set to an installed language. Then verify the API call runs after the handle is created: put a breakpoint in the Load handler and check that richTextBox1.IsHandleCreated is true before the call. If the call runs but nothing changes, confirm the Windows spellcheck setting is enabled: open Windows Settings > Privacy & security > Inking & typing personalization and make sure the spellchecking options are on. On Windows 11 the path may read slightly differently, but the setting is under typing and language options.
If the red squiggle appears but right-click shows no suggestions, the dictionary for that language may be missing. Install the language pack and restart the application. If you assigned a custom ContextMenuStrip, remove it to restore the Windows menu. If you are using a third-party library, check that the dictionary file is copied to the output directory and that the library version matches your target framework.
If the application crashes on the API call, check the P/Invoke signature and the message constant. EM_SETLANGOPTIONS is 0x0450 and the spellcheck flag is 0x00000800. A wrong constant will not crash but will have no effect; a wrong signature can crash. Keep the call inside a try/catch during development to see the exception.
Frequently Asked Questions
Does Windows Forms have a built-in spellcheck property?
No. There is no spellcheck property on TextBox or RichTextBox. Spellchecking comes from the Windows text services framework, which you enable on a RichTextBox through the API call described above.
Can I use spellcheck with a plain TextBox?
Not through the Windows integration. You need a RichTextBox or a third-party spellcheck library that supports TextBox controls.
Why does the red squiggle not appear even after the API call?
The most likely causes are that the control is not a RichTextBox, the call ran before the handle was created, or the language set on the control is not installed in Windows. Check those three first.
Does spellcheck work on Windows 10 and Windows 11?
Yes, the text services framework and spellchecking are part of both Windows 10 and Windows 11. The exact wording of the Windows language settings can differ between versions, but the control-side code is the same.
Can I customize the suggestions menu?
The suggestions menu is provided by Windows. If you replace it with your own ContextMenuStrip, you lose the built-in suggestions. For custom behavior, keep the default menu and add your own items elsewhere, or use a third-party library that exposes its own menu.
Do I need to ship a dictionary with my application?
With the Windows integration, no. The dictionary comes from the installed Windows language pack. With a third-party library, yes, you usually need to include a dictionary file and copy it to the output directory.