Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在多个拼写框中使用拼写检查_C#_Wpf_Winforms - Fatal编程技术网

C# 在多个拼写框中使用拼写检查

C# 在多个拼写框中使用拼写检查,c#,wpf,winforms,C#,Wpf,Winforms,我想使用这个正则表达式来更改从WCF工具箱导入的所有拼写框spellbox。该方法将用户输入更改为标题大小写,因此每个单词的开头都是大写字母。我想在win from上的所有拼写文本框上使用它,而不是在每个文本框中重新键入相同的函数。在我的WinForms项目中使用它的最佳方式是提高效率,而不必在我的所有文本框上使用它,如15 由于我还使用了WCF拼写框并将其集成到我的WinForms项目中,因此我也无法使用拼写框上的。在我的拼写框上选择,由于它是首先在WPF文本框上创建的,因此无法按预期工作。那

我想使用这个正则表达式来更改从WCF工具箱导入的所有拼写框
spellbox
。该方法将用户输入更改为标题大小写,因此每个单词的开头都是大写字母。我想在win from上的所有拼写文本框上使用它,而不是在每个文本框中重新键入相同的函数。在我的WinForms项目中使用它的最佳方式是提高效率,而不必在我的所有文本框上使用它,如15

由于我还使用了WCF拼写框并将其集成到我的WinForms项目中,因此我也无法使用拼写框上的
。在我的拼写框上选择
,由于它是首先在WPF文本框上创建的,因此无法按预期工作。那么,我如何才能在多个
拼写框上使用此功能,以及如何使用
。选择
方法,就像在WPF
文本框上一样

string myText = txt_HouseName.Text;
var regex = new Regex(@"[^a-zA-Z0-9\s]");// regex to change user input into Title Case.

if (myText.Equals("") || (regex.IsMatch(myText.ToString()))) // validate that the input is not a char or or null
{
    MessageBox.Show("Please enter a valid value, no special chars or leaving this blank!!!!");
}

else
{
   txt_HouseName.Text = System.Threading.Thread.CurrentThread.CurrentCulture.TextInf‌‌o.ToTitleCase(txt_HouseName.Text.ToLow‌er());
                txt_HouseName.Focus();
                txt_HouseName.Select(txt_HouseName.Text.Length, 0);

                //Move Cursor to location of where error
}

为什么需要为所有文本框重复代码?只需创建一个接收文本框作为参数的方法。@PanagiotisKanavos是的,我认为,我对winforms Sorry是新手。我是否应该在方法内部创建一个变量,比如“myText=param.Text”?只是不知道如何链接所有的拼写框?而且我不能对spelBox使用select方法。感谢如果您是Windows窗体的新手,请确保首先阅读验证和Windows窗体的一般内容。这将节省大量的精力重新实现已经存在的功能。