The below is my program so far
Upon clicking the button a series of letters are displayed to the screen.Code:Public Class Form1 Private Display As Boolean Private WithEvents tmr As Windows.Forms.Timer Private NewChar As Char Private fnt As New Font(Me.Font.FontFamily, 72, FontStyle.Bold, GraphicsUnit.Point) Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. tmr = New Windows.Forms.Timer tmr.Interval = 5000 ' 5 seconds = 5000 milliseconds End Sub Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Display = False Me.Invalidate() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.KeyPreview = True tmr.Enabled = True End Sub 'What happens after 5000 ms Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles tmr.Tick ' Make static so that the random is not seeded every time Static r As New Random ' Get a random number between A(65) and Z(90). NewChar = Chr(r.Next(65, 90)) ' Make sure screen gets repainted Me.Invalidate() ' Stop the timer so that it doesn't fetch the next character automatically tmr.Stop() End Sub ' Stopping and restarting timer Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress If (Char.ToUpper(e.KeyChar) = NewChar) Then 'Start the timer so that the next character is shown in 5 seconds NewChar = ControlChars.NullChar ' < -------------------------- Me.Invalidate() tmr.Start() End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Start the timer so that the next character is shown in 5 seconds tmr.Start() Display = True Me.Invalidate() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint If Display Then Dim textSize As SizeF = e.Graphics.MeasureString(NewChar, fnt) If NewChar = ControlChars.NullChar Then Exit Sub e.Graphics.DrawString(NewChar, fnt, Brushes.Red, x:=50, y:=50) End Sub Protected Overrides Sub Finalize() MyBase.Finalize() End Sub End Class
I would like to be able to capture the time taken to press the letter shown.
Is there any way of doing this?
E.g capturing the results in a textbox?




Reply With Quote