views:

27

answers:

2

Hi all. I have a next problem. I need to represent a pressed keys combination in a text form. I got pressed keys from KeyEventArgs e... And when I try to use following code e.KeyData.ToString(); I got something like this: N, Control .... But I want to get Ctrl+N string.
I think that must be present specific format for String.Format because when i bind property with type Keys to the DataGridView I saw in the table cell string Ctrl+N. It's mean that DataGridView can do this, and i think this is not done manually...

Thanks a lot!!

A: 

According to MSDN, there is nothing built-in to do this. I suspect the grid is just substituing ", " for "+".

Kent Boogaart
+1  A: 

The Keys values are probably displayed using the TypeConverter belonging it.

If you want to emulate the behavior of the DataGridView, you should use

TypeConverter converter = TypeDescriptor.GetConverter(typeof(Keys));
string displayName = converter.ConvertToString(e.KeyData);

The Keys type is tagged with [TypeConverter(typeof(KeysConverter))], which is what GetConverter should return.

Ruben