Convert this VB code to C#?
Posted
by
Róisín Kerr Lautman
on Stack Overflow
See other posts from Stack Overflow
or by Róisín Kerr Lautman
Published on 2012-03-25T11:14:44Z
Indexed on
2012/03/25
11:29 UTC
Read the original article
Hit count: 232
I was wondering if anyone would be able to help me convert the below code to c#? From what I have read it seems to be similar however I am not sure if my 'case' statements are still able to be used?
Public Class Form1
Dim dteStart As Date
Dim dteFinish As Date
Dim span As TimeSpan
Public Sub KeyDown(ByVal Sender As System.Object, ByVal e As _
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Q
Label1.BackColor = Color.Green
dteStart = Now()
Case Keys.W
Label2.BackColor = Color.Green
Case Keys.E
Label3.BackColor = Color.Green
Case Keys.R
Label4.BackColor = Color.Green
dteFinish = Now()
span = dteFinish.Subtract(dteStart)
Label5.Text = span.ToString
End Select
End Sub
Public Sub KeyUp(ByVal Sender As System.Object, ByVal e As _
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
Select Case e.KeyCode
Case Keys.Q
Label1.BackColor = Color.Red
Case Keys.W
Label2.BackColor = Color.Red
Case Keys.E
Label3.BackColor = Color.Red
Case Keys.R
Label4.BackColor = Color.Red
End Select
End Sub
End Class
© Stack Overflow or respective owner