Advertisement
SmileCookies

11/24上課題目

Nov 24th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.17 KB | None | 0 0
  1. Public Class Form5
  2.     Dim Rnd As New Random
  3.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  4.         Timer1.Enabled = Not Timer1.Enabled
  5.     End Sub
  6.     Dim la(16) As Label
  7.     Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8.         For i = 0 To 15
  9.             la(i) = New Label
  10.             la(i).Width = 20
  11.             la(i).Height = 20
  12.             la(i).AutoSize = False
  13.             la(i).Text = ""
  14.             la(i).BorderStyle = BorderStyle.FixedSingle
  15.             la(i).BackColor = Color.Black
  16.             la(i).Left = 20 + 25 * i
  17.             la(i).Top = 188
  18.             la(i).Parent = Me
  19.         Next
  20.     End Sub
  21.  
  22.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  23.         Dim a As Int64 = Rnd.Next(2 ^ 16)
  24.         Dim b As Int64
  25.         Dim c As String
  26.         While a <> 0
  27.             b = a Mod 2
  28.             a = a \ 2
  29.             c = b & c
  30.         End While
  31.         Label1.Text = StrDup(16 - Len(c), "0") & c
  32.         For i = 0 To 15
  33.             la(i).BackColor = IIf(Mid(Label1.Text, i + 1, 1) = 1, Color.Green, Color.Black)
  34.         Next
  35.     End Sub
  36. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement