esquima Posted October 23, 2007 at 03:05 PM Report Share #142417 Posted October 23, 2007 at 03:05 PM Há alguma possibilidade de quando se for escrever algo numa textbox a 1ª letra ser maiúscula??? Mesmo que o utilizador meta uma minúscula ela passe para maiúscula. Link to comment Share on other sites More sharing options...
morsa Posted October 23, 2007 at 03:44 PM Report Share #142424 Posted October 23, 2007 at 03:44 PM Usas uma masked text box e resolves isso fácil ou utilizas o evento keypress ou textchanged da textbox. A máscara será MaskedTextBox1.Mask = ">L#######" (o uso do '>' faz com que a primeira letra seja convertida em maiúscula! e L -> obriga a que o primeiro caracter seja uma letra) No caso de ser como evento deve ser relativamente simples (não testei e foi escrito na hora) Private Sub xisUp(ByVal xxxX) Handles TextBox1.TextChanged TextBox1.Text.Chars(0) = TextBox1.Text.Chars(0).ToUpper End Sub Espero ter ajudado! 1abraço Link to comment Share on other sites More sharing options...
esquima Posted October 23, 2007 at 04:06 PM Author Report Share #142426 Posted October 23, 2007 at 04:06 PM Morsa desculpa la a minha pergunta...onde e que eu defino isso da mask em cada textbox???ja agora se existe algum sitio onde possa obrigar todas as textbox a fazer isso...por senao tenha de bater mto codigo Link to comment Share on other sites More sharing options...
morsa Posted October 26, 2007 at 01:56 PM Report Share #143017 Posted October 26, 2007 at 01:56 PM Ora bem, estive a rever a cena e o que consegui foi isto: Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp, TextBox2.KeyUp Dim txb As New TextBox txb = sender Try ' se é um caractere If e.KeyValue > 64 And e.KeyValue < 91 Then If txb.Text.Length = 1 Then ' é a primeira letra da TextBox txb.Text = Char.ToUpper(txb.Text.Chars(0)) ' coloca o cursor na ultima posição da textbox txb.Select(txb.TextLength, 1) Else ' não é a primeira letra mas podemos sempre alterar a primeira letra ' converter a string Dim s As String = "" ' só o primeiro caracter s = Char.ToUpper(txb.Text.Chars(0)) ' texto convertido txb.Text = s + txb.Text.Substring(1).ToLower ' o to lower faz com que as restantes letras sejam minúsculas também ' coloca o cursor na ultima posição da textbox txb.Select(txb.TextLength, 1) End If End If Catch ex As Exception End Try End Sub Espero que resolva. Há uma pequena latência também entre o largar da tecla (uma vez que o evento está associado ao keyUp...) e a conversão! Quanto a usares para várias textbox em simultâneo é uma questão de olhares para o cabeçalho da função (textbox1.keyup, textbox999.keyup - funciona na txt box 1 e txt box 999)! 😄 1abraço Link to comment Share on other sites More sharing options...
Weasel Posted October 26, 2007 at 03:02 PM Report Share #143033 Posted October 26, 2007 at 03:02 PM morsa, um bocadinho confuso esse código não ? Pode-se capitalizar as textboxes depois de clicar num butão ? Se sim faz assim, é mais rápido e simples e apanha todas as textboxes sem mais códigos: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each c As Control In Me.Controls If TypeOf c Is TextBox Then c.Text = c.Text.Substring(0, 1).ToUpper & c.Text.Substring(1) End If Next End Sub Knowledge to the masses Link to comment Share on other sites More sharing options...
esquima Posted October 26, 2007 at 04:27 PM Author Report Share #143051 Posted October 26, 2007 at 04:27 PM eu nao queria no botao.... tou com um codigo que me mete as primeiras letras maisciulos so que o que ele me ta a farer e isto... ex: Ontem Gostei Muito Do filme e queria Ontem gostei muito do filme tenho o meu codigo no textchanged Link to comment Share on other sites More sharing options...
Weasel Posted October 26, 2007 at 04:36 PM Report Share #143052 Posted October 26, 2007 at 04:36 PM Podes fazer Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus If (TextBox1.TextLength > 0) Then TextBox1.Text = TextBox1.Text.Substring(0, 1).ToUpper & TextBox1.Text.Substring(1) End If End Sub Mas mostra lá esse código pode ser que se dê um jeito 😄 Knowledge to the masses Link to comment Share on other sites More sharing options...
esquima Posted October 26, 2007 at 05:21 PM Author Report Share #143063 Posted October 26, 2007 at 05:21 PM Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles TextBox1.TextChanged Dim selStart As Integer Dim selLength As Integer selStart = Me.TextBox1.SelectionStart selLength = Me.TextBox1.SelectionLength Me.TextBox1.Text = StrConv(Me.TextBox1.Text, VbStrConv.ProperCase) Me.TextBox1.SelectionStart = selStart Me.TextBox1.SelectionLength = selLength End Sub Link to comment Share on other sites More sharing options...
Joca Posted October 28, 2007 at 10:09 PM Report Share #143647 Posted October 28, 2007 at 10:09 PM O código da morsa pode ser perfeitamente aplicado no teu evento TetxChanged da TextBox... Ou tem de ser mesmo do tipo Integer?? No meu programa funcionou perfeitamente. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles TextBox1.TextChanged, TextBox2.TextChanged Dim txb As New TextBox txb = sender Dim s As String = "" s = Char.ToUpper(txb.Text.Chars(0)) txb.Text = s + txb.Text.Substring(1).ToLower txb.Select(txb.TextLength, 1) End Sub Tal como ela diz, na mesma linha de código onde se encontra o evento TextChanged, podes escrever o nome de TODAS as TextBoxes. Link to comment Share on other sites More sharing options...
esquima Posted October 29, 2007 at 05:35 PM Author Report Share #143781 Posted October 29, 2007 at 05:35 PM joca eu utilizei a tua maneira e e mesmo isso que eu quero so que quando tenho la um texto e apago tudo quando acabo de apagar ele da me um erro: index was outside the bounds of the array na linha: s=char.toupper(txb.text.char(0)) Link to comment Share on other sites More sharing options...
Tiago Salgado Posted October 30, 2007 at 09:22 AM Report Share #143938 Posted October 30, 2007 at 09:22 AM Terás que por uma validação antes de fazeres a conversão para maiuscula. Algo do tipo If Not String.IsNullOrEmpty(txb.Text.Trim) Then ' converte pra maiuscula End If Link to comment Share on other sites More sharing options...
esquima Posted October 30, 2007 at 02:33 PM Author Report Share #143977 Posted October 30, 2007 at 02:33 PM obrigado , ja bomba 😉 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now