TextBox中的句子大小写或正确的大小写

Kis*_*mar 0 .net vb.net textbox

我想让我TextBox输入我输入的文本Sentence Case(ProperCase)..但我不想在像Lost Focus或的事件中编写任何代码KeyPress.

默认情况下,只要用户输入或输入文本框,每个单词的第一个字母就会自动转换为UpperCase.

Phi*_*ove 7

我不知道如何在WinForms中执行此操作而不在事件中放置一些代码.CharacterCasingTextBox 的属性允许您强制输入大写或小写的所有字符,但不能强制执行Proper Casing.顺便说一下,在一个事件中执行它是一行代码:

TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
Run Code Online (Sandbox Code Playgroud)

跨多个文本框执行此操作的更通用的处理程序涉及将大量事件附加到相同的代码:

'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
Run Code Online (Sandbox Code Playgroud)

在ASP.NET中,您无需代码即可完成此操作 ; 有一个名为的CSS属性text-transform,该属性的值之一是capitalize.当应用于文本输入元素时,它使每个单词的第一个字母为大写.