.net 文本框中的句子大小写或适当大小写

.net 文本框中的句子大小写或适当大小写,.net,vb.net,textbox,.net,Vb.net,Textbox,我希望我的文本框将我输入的文本设置为句子大小写(ProperCase)。。但是我不想在像失去焦点或按键这样的事件中编写任何代码 默认情况下,每当用户输入或键入文本框时,每个单词的第一个字母都应自动转换为大写字母。我不知道在WinForms中如何做到这一点,而不在事件中添加一些代码。文本框的CharacterCasing属性允许您强制输入大写或小写的所有字符,但不能执行正确的大小写。顺便说一句,在事件中执行此操作只需一行代码: TextBox1.Text = StrConv(TextBox1.Te

我希望我的
文本框
将我输入的文本设置为
句子大小写(ProperCase)
。。但是我不想在像
失去焦点
按键
这样的事件中编写任何代码


默认情况下,每当用户输入或键入文本框时,每个单词的第一个字母都应自动转换为大写字母。我不知道在WinForms中如何做到这一点,而不在事件中添加一些代码。文本框的
CharacterCasing
属性允许您强制输入大写或小写的所有字符,但不能执行正确的大小写。顺便说一句,在事件中执行此操作只需一行代码:

TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
跨多个文本框执行此操作的更通用的处理程序涉及将多个事件附加到同一代码:

'Attach multiple events to this handler
Private Sub MakeProperCase(sender As Object, e As EventArgs) Handles _
    TextBox1.LostFocus, TextBox2.LostFocus, TextBox3.LostFocus

    'Get the caller of the method and cast it to a generic textbox
    Dim currentTextBox As TextBox = DirectCast(sender, TextBox)
    'Set the text of the generic textbox to Proper Case
    currentTextBox.Text = StrConv(currentTextBox.Text, VbStrConv.ProperCase)

End Sub

在ASP.NET中,您可以这样做;有一个CSS属性叫做
文本转换
,该属性的值之一是
大写
。当应用到文本输入元素时,它会使每个单词的第一个字母大写。

我不知道在WinForms中如何做到这一点,而不在事件中放入一些代码。文本框的
CharacterCasing
属性允许您强制输入大写或小写的所有字符,但不能执行正确的大小写。顺便说一句,在事件中执行此操作只需一行代码:

TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
跨多个文本框执行此操作的更通用的处理程序涉及将多个事件附加到同一代码:

'Attach multiple events to this handler
Private Sub MakeProperCase(sender As Object, e As EventArgs) Handles _
    TextBox1.LostFocus, TextBox2.LostFocus, TextBox3.LostFocus

    'Get the caller of the method and cast it to a generic textbox
    Dim currentTextBox As TextBox = DirectCast(sender, TextBox)
    'Set the text of the generic textbox to Proper Case
    currentTextBox.Text = StrConv(currentTextBox.Text, VbStrConv.ProperCase)

End Sub

在ASP.NET中,您可以这样做;有一个CSS属性叫做
文本转换
,该属性的值之一是
大写
。当应用于文本输入元素时,它使每个单词的第一个字母大写。

这种情况下有两个控件:cbodestitation和txtUser。当你打字的时候,它会让你想做什么

Private Sub properCase_TextChanged(sender As Object, e As System.EventArgs) _ 
        Handles cboDestination.TextChanged, txtUser.TextChanged
        Dim n As Integer = sender.SelectionStart
        sender.Text = StrConv(sender.Text, VbStrConv.ProperCase)
        sender.SelectionStart = n
End Sub

本例中有两个控件:cboDestination和txtUser。当你打字的时候,它会让你想做什么

Private Sub properCase_TextChanged(sender As Object, e As System.EventArgs) _ 
        Handles cboDestination.TextChanged, txtUser.TextChanged
        Dim n As Integer = sender.SelectionStart
        sender.Text = StrConv(sender.Text, VbStrConv.ProperCase)
        sender.SelectionStart = n
End Sub

我可能错了,但我认为唯一的方法是在使用事件输入文本时检查文本框的值,并相应地更新文本。我已经尝试使用区域性类,但我认为这将对处理造成沉重负担。您正在处理用户输入。在用户注意到之前,您有1亿个cpu周期来完成任务。感谢这个问题-我投票通过了这个问题,因为如果回答我可能是错的,我不会有任何线索,但我认为唯一的方法是在使用事件输入文本时检查文本框的值,并相应地更新文本。我已经尝试使用文化类,但我认为这将对处理造成沉重负担。您正在处理用户输入。在用户注意到之前,您有1亿个cpu周期来完成任务。感谢这个问题-我投票支持这个问题,因为我没有给出答案的线索