Most of the functions in my WinForms application have a key press alternative. There are a lot of them. At the moment I am handling this in a switch statement. My code analyzers tell me that this code is un-maintainable to varying degrees of nasty. I have to agree. I would extract the handling code out to separate methods but in most cases this is only a line or two and it does not really help me get a handle on things…..
Is there are better way to handle this of am I stuck with a huge switch?
Thanks in advance
Somewhere in the code, soon or later, you will need to make
swicth/caseorif/else, or whatever. So pushing actual handling code for every Key or Key combination to separate function is already good step.You may be can other “nice” stuff: make a dictionary where
Key: is keyboard key
Value: delegate to call on that key press
And basically what you will need to do is to say, pseudocode!!
Hope this will give some hints.
Regards.