У меня следующая проблема. Мне нужно представить комбинацию нажатых клавиш в текстовом виде. Я получил нажатые клавиши от KeyEventArgs e ...
И когда я пытаюсь использовать следующий код
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!!
Значения Keys, вероятно, отображаются с помощью принадлежащего ему TypeConverter.
Если вы хотите эмулировать поведение DataGridView, вам следует использовать
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Keys));
string displayName = converter.ConvertToString(e.KeyData);
Тип Keys помечен [TypeConverter(typeof(KeysConverter))]
, который и должен возвращать GetConverter
.
Согласно MSDN , для этого нет ничего встроенного. Я подозреваю, что сетка просто заменяет "+" на "" ".