Reputation: 589
I am making a C# Windows Form Application in Visual Studio 2012. I want add a textbox with spell checking capabilities. Could you please explain me the process for it ?
Upvotes: 12
Views: 22950
Reputation: 266
If you are using .NET4 you can add the References System.Xaml and WindowsFormsIntegration to your Winforms project.
This allows you to find the ElementHost in you Toolbox. By using the ElementHost you can use WPF objects in your WinForms project.
System.Windows.Forms.Integration.ElementHost elementHost1 = new System.Windows.Forms.Integration.ElementHost();
System.Windows.Controls.TextBox textBox = new System.Windows.Controls.TextBox();
textBox.SpellCheck.IsEnabled = true;
elementHost1.Child = textBox;
Upvotes: 14
Reputation: 11
I know old link but Buzzzzz is correct. WinForms can't do it but it is really easy to create a wpf textbox or richtext box control and add it to your WinForms. Finding that darn property to tell the textbox to spell check is tricking but seriously,
You now have a control in your toolbox named whatever you names it. Drag and drop the control from the toolbox and there you go. To talk to it the defaults would be userControl1.TextBox.Text
Oh almost forgot. The Winforms and WPF are not all that friendly with each other and you will have to compile to remove the red line squiggles if they appear.
Upvotes: 1
Reputation: 1214
There is no WinForms capability for that. But, if you want to reuse it as a text box, Create a WPF UserControl and put a WPF TextBox in there. enable spell check. If you drag and drop an element host once, it will automatically add necessary references, after that, you will be able to see your user controls in the toolbox. once the usercontrol is visible, all you have to do is drag and drop it, it will automatically create an element host for you and put the wpf usercontrol in it.
Upvotes: 1
Reputation: 8221
There is no built-in spellcheck capability on the Windows Forms textbox.
The best thing you can do is probably embed an WPF textbox in your form. Hans Passant gives a very thorough answer in this post on how to achieve that.
Upvotes: 7
Reputation: 645
Basically, you just need to set the SpellCheck.IsEnabled
property to 'true'. Like this:
TextBox textBox = new TextBox();
textBox.SpellCheck.IsEnabled = true;
You can find this property in the System.Windows.Controls
namespace, and reference it like this:
using System.Windows.Controls;
Editorial: I would strongly suggest using WPF
over Winforms
if that is an option you can explore. Winforms
had its day once, but for more modern development, WPF
is a much more powerful platform.
Upvotes: -1