VBでストループカラーワードテストを作成したいです.
上に問題(例:「あか」という文字が青色で書かれている)下に答え(例:あか)
上と問題に対して下の答えがあっていれば右クリック,間違っていれば左クリックを押します.右もしくは左クリックされるか,問題が表示されてから2秒立つか,すると次の問題と答えが表示されるというものを作ろうとしています.
現在,問題をランダムな文字と色の組み合わせで表示させること,下の答えをランダムな文字で表示させること,これらの文字を2秒毎に表示させることが下記のコードでできています.
しかし,クリックを押してから2秒後というのがうまくいきません.現在のコードではクリックを押して2秒立たなくても問題が変わってしまいます.
おそらくタイマーイベントの2秒後というのが動き続けているのかなと思うのですが,どのように変えればよいでしょうか.アドバイスをお願いします.
以下現在のコードです.
Public Class Form1
Private Sub colorword1()
Dim a() As String = New String() {"あか", "あお", "みどり"}
Randomize()
Label1.Text = a(Math.Floor(3 * Rnd()))
RichTextBox1.Text = a(Math.Floor(3 * Rnd()))
RichTextBox1.SelectionAlignment = HorizontalAlignment.Center
End Sub
Private Sub colorword2()
Dim rnd As New System.Random()
' 0 以上 2 未満の乱数を取得する(0,1,2がランダムに判定される)
Dim iResult As Integer = rnd.Next(2)
If iResult = 0 Then
RichTextBox1.ForeColor = Color.Red '0の時は赤
ElseIf iResult = 1 Then
RichTextBox1.ForeColor = Color.Blue '1の時は青
ElseIf iResult = 2 Then
RichTextBox1.ForeColor = Color.Green '2の時は緑
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.Timer1.Interval = 1000 * 2 Call colorword1() Call colorword2() End Sub Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick Select Case e.Button Case Windows.Forms.MouseButtons.Left Call colorword1() Call colorword2() Case Windows.Forms.MouseButtons.Right Call colorword1() Call colorword2() End Select End Sub Private Function RGB(p1 As Integer) As Color Throw New NotImplementedException End Function Private Function RGB(p1 As Integer, p2 As Integer, p3 As Integer) As Color Throw New NotImplementedException End Function
End Class
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/18 02:35