c# - ShortcutKey from string -
i want provider user option set toolstripmenuitem.shortcutkeys
via configuration file, i've figured out need somehow transform string
keys
.
i've already found how simple values using enum.parse
, won't recognize formats like:
ctrl+i
(with space @ end)i
ctrl+alt+esc
q: there standardized way of parsing stings (ctrl+i
) keys
?
i'd avoid writing own function split text pieces , handle each case/special string separately.
the string see in properties window shortcutkeys property generated typeconverter. can use type converter in own code well. this:
var txt = "ctrl+i"; var cvt = new keysconverter(); var key = (keys)cvt.convertfrom(txt); system.diagnostics.debug.assert(key == (keys.control | keys.i));
do beware i
or ctrl+alt+escape
not valid short-cut keys. keysconverter not complain, you'll exception when assign shortcutkeys property. wrap both try/except catch invalid config data.
Comments
Post a Comment