Visual Studio autogenerated code
-
This is the base code vs generates to check for special keys, on a Smart Device project:
private void Form1\_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == System.Windows.Forms.Keys.Up)) { // Subir oscilador // Subir } if ((e.KeyCode == System.Windows.Forms.Keys.Down)) { // Bajar oscilador // Bajar } if ((e.KeyCode == System.Windows.Forms.Keys.Left)) { // Izquierda } if ((e.KeyCode == System.Windows.Forms.Keys.Right)) { // Derecha } if ((e.KeyCode == System.Windows.Forms.Keys.Enter)) { // Entrar } }
A Pocket PC is full of power, so let's check for every possible key.
This might not be a horror at all. Maybe it's intended this way (I don't know as I never used a Pocket PC). If the user presses multiple directions, several
if
s are true and the code for each of them should be executed. Otherwise diagonal directions would be impossible because it would accept only a single directional key at once. -
This might not be a horror at all. Maybe it's intended this way (I don't know as I never used a Pocket PC). If the user presses multiple directions, several
if
s are true and the code for each of them should be executed. Otherwise diagonal directions would be impossible because it would accept only a single directional key at once. -
You would delete the auto-generated code anyway wouldn't you? Actually isn't there a file (or files) that contain such things and you can change them there?
PIEBALDconsult wrote:
You would delete the auto-generated code anyway wouldn't you? Actually isn't there a file (or files) that contain such things and you can change them there?
Of course, I can change the code, the same way you would change the code on all the horrors published here. Isn't this forum to publish horrors you find over there? I think this is a reply horror. :laugh:
-
...yes, thatwould be true
-
It's not a big horror, its just funny to see it on Visual Studio. The correct implementation would be:
private void Form1\_KeyDown(object sender, KeyEventArgs e) { switch(e.KeyCode) { case System.Windows.Forms.Keys.Up: // Subir oscilador // Subir break; case System.Windows.Forms.Keys.Down: // Bajar oscilador // Bajar break; case System.Windows.Forms.Keys.Left: // Izquierda break; case System.Windows.Forms.Keys.Right: // Derecha break; case System.Windows.Forms.Keys.Enter: // Entrar break; } }
-
...yes, thatwould be true
Even if multiple keys where able to be captured at the same time, using many == will not be a solution. After all, if the keys where combined using the | operator, as happens with flags, the right way to check the values will be using: if ((parameter & condition) == condition) or if ((parameter & condition) != 0) But that's not the case with keys. So, this is an ugly code (but not an horror in my opinion).
-
it is a horror that this visible code is so poor. :mad: What about the non-visible code. Shame on Microsoft!!! X|
Press F1 for help or google it. Greetings from Germany
-
If the first
if
is true, for example, why bother testing all the others which follow? It's dopey code.Steve
That many bunch of
if
s could have been elegantly presented with a decentswitch
block.Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
I mean the code we cant look at, like the soruce code of windwos or Office. :-\
Press F1 for help or google it. Greetings from Germany
KarstenK wrote:
we cant look at, like the soruce code of windwos or Office
But we can feel it and enjoy it with timely patches and service packs.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
adgonz wrote:
multiple events are fired.
The application goes haywire and user runs amuck helter-skelter.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
KarstenK wrote:
we cant look at, like the soruce code of windwos or Office
But we can feel it and enjoy it with timely patches and service packs.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
I don't see any horror here. What do you want to do if you need to check for those keys?