Allow entering uppercase only

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Is there an easy way to ensure that only Upper case characters are entered
into a tex box ?

I assume one would use the OnKeypress event ?

Thanks
 
Rob,

Why do you make it the user difficult, if you do something as this in the
validating event than it does not matter

textbox1.text = textbox1.text.ToUpper

Cor
 
Rob said:
Is there an easy way to ensure that only Upper case characters are
entered into a tex box ?

You could try this:

\\\
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

TextBox1.SelectedText = UCase(e.KeyChar)
e.Handled = True

End Sub
///

That seems to work fine. Note that text that the user pastes in will not be
affected by this so you probably want to follow Cor's recommendation too
when the user clicks the OK button on your form.
 
Rob said:
Is there an easy way to ensure that only Upper case characters are entered
into a tex box ?

Set the textbox' 'CharacterCasing' property to 'Upper'.
 
we not looking back in vb6. u may take alook at cor lightert sample.
so let move on to vb.net. 8-)
 
Supra said:
we not looking back in vb6.

I realise that (and I also realise that it was a very VB6-style answer).

But it did directly answer the question, whereas I thought Cor offered a
slightly different solution to the one the OP has specifically asked for. I
know I've had situations where users of my system have asked for the values
to be entered in upper-case, and if they were displayed in lower-case until
they clicked the OK button then they simply wouldn't be happy. Users -- bah!

Anyway, Herfried's answer is clearly the best of all of them. :-)
 
Back
Top