[problem!]KeyPress event - wrong e.KeyChar.ToString on W98

W

Wiktor Zychla

in my application I sometimes use KeyPress event. in the event handler I
have to check the char the user is trying to type.

in NTs everything is correct. however on W98 I've noticed that the character
given in

e.KeyChar (e is KeyPressEventArgs of course)

is NOT correctly converted ToString() when I type polish specific letters!
instead of the letter 'polish l' I get '3', instead of 'polish z' I get '?'
and so on.

it seems that the KeyChar reported in KeyPressEventHandler cannot handle
these specific letters. this bug seems to stick deeply inside the .NET
libraries because in any other case the polish specific letters are
correctly converted to their string equivalents.

I consider this as a painful bug, however I would really like to hear from
an expert about it. I am also really curious if this bug affects other
localized versions of W98 (for example german, french, turkish etc.)

Regards,
Wiktor Zychla

shortest example:

using System;
using System.Windows.Forms;
using System.Drawing;

public class CForm : Form
{
TextBox t;

public CForm()
{
t = new TextBox();
t.KeyPress += new KeyPressEventHandler( tkp );
this.Controls.Add( t );
}

// type any culture specific letter
// in polish W98 you will not see the letter you've typed
// it seems to be a severe bug
void tkp( object sender, KeyPressEventArgs e )
{
MessageBox.Show( e.KeyChar.ToString() );
}

public static void Main()
{
Application.Run( new CForm() );
}
}
 
N

Nick Bunton

Could you not just try and get the key pressed and do the
necessary action from a switch or if statement.

if (e.KeyChar == (char)13)
// Enter Key Pressed




-----Original Message-----
in my application I sometimes use KeyPress event. in the event handler I
have to check the char the user is trying to type.

in NTs everything is correct. however on W98 I've noticed that the character
given in

e.KeyChar (e is KeyPressEventArgs of course)

is NOT correctly converted ToString() when I type polish specific letters!
instead of the letter 'polish l' I get '3', instead of 'polish z' I get '?'
and so on.

it seems that the KeyChar reported in
KeyPressEventHandler cannot handle
 
W

Wiktor Zychla

if (e.KeyChar == (char)13)
// Enter Key Pressed

I cannot because I would get wrong results. for example, the 'polish l'
letter is reported as the key '3' etc.
the other but polish specific keys are reported correctly (like the Enter
you've mentioned).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top