我修复了我的语法, 如果选中复选框,我怎样才能显示总数?
Option Strict On
Option Explicit On
Public Class Form1
Private Player1 As String
Private Player2 As String
Private Player1Wins As Integer = 1
Private Player2Wins As Integer = 1
Private Tie As Integer = 1
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmMainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Player1 = InputBox("Enter Player 1's Name: ")
lblPlayer1.Text = (Player1 + "'s Score:")
Player2 = InputBox("Enter Player 2's Name:")
lblPlayer2.Text = (Player2 + "'s Score:")
End Sub
Private Sub btnRoll_Click(sender As Object, e As EventArgs) Handles btnRoll.Click
' game of rolling dice
Dim randGen As New Random
Dim intNum1 As Integer
Dim intNum2 As Integer
Dim intNum3 As Integer
Dim intNum4 As Integer
Dim intTotal As Integer
Dim intTotal2 As Integer
' make random integer from 1 through 6
intNum1 = randGen.Next(1, 7)
intNum2 = randGen.Next(1, 7)
intNum3 = randGen.Next(1, 7)
intNum4 = randGen.Next(1, 7)
' display the right image in picDie1
Select Case intNum1
Case 1
picDie1.Image = picOneDot.Image
Case 2
picDie1.Image = picTwoDots.Image
Case 3
picDie1.Image = picThreeDots.Image
Case 4
picDie1.Image = picFourDots.Image
Case 5
picDie1.Image = picFiveDots.Image
Case 6
picDie1.Image = picSixDots.Image
End Select
' display the right image in picDie2
Select Case intNum2
Case 1
picDie2.Image = picOneDot.Image
Case 2
picDie2.Image = picTwoDots.Image
Case 3
picDie2.Image = picThreeDots.Image
Case 4
picDie2.Image = picFourDots.Image
Case 5
picDie2.Image = picFiveDots.Image
Case 6
picDie2.Image = picSixDots.Image
End Select
' display the right image in picDie3
Select Case intNum3
Case 1
picDie3.Image = picOneDot.Image
Case 2
picDie3.Image = picTwoDots.Image
Case 3
picDie3.Image = picThreeDots.Image
Case 4
picDie3.Image = picFourDots.Image
Case 5
picDie3.Image = picFiveDots.Image
Case 6
picDie3.Image = picSixDots.Image
End Select
' display the right image in picDie4
Select Case intNum4
Case 1
picDie4.Image = picOneDot.Image
Case 2
picDie4.Image = picTwoDots.Image
Case 3
picDie4.Image = picThreeDots.Image
Case 4
picDie4.Image = picFourDots.Image
Case 5
picDie4.Image = picFiveDots.Image
Case 6
picDie4.Image = picSixDots.Image
End Select
' calculate and display total number of dots
intTotal = intNum1 + intNum2
lblTotal.Text = intTotal.ToString()
intTotal2 = intNum3 + intNum4
lblTotal2.Text = intTotal2.ToString()
If intTotal > intTotal2 Then
MessageBox.Show("Player1 Wins")
lblWins.Text = CStr(Player1Wins)
Player1Wins = Player1Wins + 1
End If
If intTotal2 > intTotal Then
MessageBox.Show("Player2Wins")
lblWins2.Text = CStr(Player2Wins)
Player2Wins = Player2Wins + 1
End If
If intTotal = intTotal2 Then
MessageBox.Show("Tie")
lblTies.Text = CStr(Tie)
Tie = Tie + 1
End If
End Sub
End Class
答案 0 :(得分:0)
不知道您是如何尝试显示结果的,不管这是“消息框”还是“标签”,但是我会如何做到这一点:
使用标签/文本框:继续计算并显示总计,然后将此代码放在复选框的Changed事件中。
If CheckBox1.Checked = True Then
lblTotal.Visible = True
Else
lblTotal.Visible = False
如果使用消息框,您可以使用MessageBox.Show(" Total is:"& MyTotalVariable)