Converting Keystrokes in upper case

  • Thread starter Thread starter Manish
  • Start date Start date
M

Manish

In my application there is need for only upper case chars..
Currently I am making entry to upper case when user leaves focus of the
text control.
I want to do some modification here...When user enters any char in
small case...during that entry it should convert in upper case...
It is very easy in VB6..In VB6 you just need to convert the Ascii value
to char ---> then to Ucase ---> then char to Ascii again...this can be
done in keypress event...

I am facing problem in C# how to do this ?

Is there anybody to help..................

please write solution to (e-mail address removed)
Thanks in advance....
Regards
Manish
 
What you'll want to do is handle the KeyPress event, and handle the
upper case code there. That will result in changing every time a key is
pressed.

Lowell
 
Actually I did in keypress event in c#..
we get actual key char from e.KeyChar..This is the readonly property..If
I convert any keyboard input in ucase..how do I assign to it again?

If I assgin to txtBox.text = e.KeyChar.ToString().ToUpper();
My control goes to the start of the text box when I type any char in
control....

If anybody knows solution to this problem please answer....

Thanx in advance

Manish
 
Hi Manish,

Does this do what you need?

private void textBox1_TextChanged(object sender, System.EventArgs e)
{
int start = this.textBox1.SelectionStart;
this.textBox1.Text = this.textBox1.Text.ToUpper();
this.textBox1.SelectionStart = start;
}

--Liam.
 
I think the simplest way is to set the CharacterCasing property,
MyTextBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
and then it all happens automatically.

Chris Jobson
 
The CharacterCasing property is the easiest way to achieve what you
want this time.

For some other time when you have to do more sophisticated processing
than just upper casing characters, the answer is that you don't
_change_ the character in e.KeyChar. Instead, you "swallow up" the
typed character and use SendKeys.Send() to send a different keystroke
to the application.

Props to Claes Bergefal who taught me that one.
 
Back
Top