469,613 Members | 2,028 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Character Casing in Combo

How to make a ComboBox to display characters only in Upper or Lower Case as
you type?

I was trying to override OnKeyDown and OnKeyPress but coudn't figure it
out. The problem is that in OnKeyPress
new key value is not writed in the Combo.Text until the event is executed.
Nov 16 '05 #1
3 2754
Hi UmmagummA,

What you do in the KeyPressEvent is set e.Handled = true to prevent the
characters ever reaching the ComboBox. Instead add a character of your
own.

Something like this might work for you, given a ComboBox b and its
KeyPressEvent b_Press

private void b_Press(object sender, KeyPressEventArgs e)
{
if(Char.IsLetter(e.KeyChar))
{
e.Handled = true;
string s = e.KeyChar.ToString();
b.Text += s.ToUpper();
b.SelectionStart = b.Text.Length;
}
}
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Even better, using Char.ToUpper

if(Char.IsLetter(e.KeyChar))
{
e.Handled = true;
b.Text += Char.ToUpper(e.KeyChar);
b.SelectionStart = b.Text.Length;
}
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Huge Thanks!

When I saw it, I tought, why I didn't think of it :))
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Visual Systems AB \(Martin Arvidsson\) | last post: by
3 posts views Thread by =?Utf-8?B?TWlrZSBPS0M=?= | last post: by
2 posts views Thread by =?Utf-8?B?R3dlblA=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.