By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,705 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,705 IT Pros & Developers. It's quick & easy.

Converting Keystrokes in upper case

P: n/a
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 ma*******@rediffmail.com
Thanks in advance....
Regards
Manish

Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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


Manish wrote:
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 ma*******@rediffmail.com
Thanks in advance....
Regards
Manish

Nov 16 '05 #2

P: n/a
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a
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.

"Manish Khobragade" <ma*******@rediffmail.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

P: n/a
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
"Manish" <ma*******@rediffmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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 ma*******@rediffmail.com
Thanks in advance....
Regards
Manish

Nov 16 '05 #5

P: n/a
Couldn't you simply set the Textbox's CharacterCasing property to
"CharacterCasing.Upper"

See
http://msdn.microsoft.com/library/de...asingtopic.asp

Shariq Khan
sh****@shariqkhan.com
"Liam McNamara" <re***@newsgroup.net> wrote in message
news:6i**************@news-srv1.fmr.com...
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.

"Manish Khobragade" <ma*******@rediffmail.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #6

P: n/a
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.

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.