✔ 最佳答案
Public Class Form1
Private PictureBox1(10) As PictureBox
Private Image1(1) As Image
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To 10
InitializePictureBox(PictureBox1(i), 60 * (i + 1), 100)
Next
Image1(0) = System.Drawing.Image.FromFile("Image1.bmp")
Image1(1) = System.Drawing.Image.FromFile("Image2.bmp")
End Sub
Private Sub InitializePictureBox(ByRef picbox, ByVal left, ByVal top)
picbox = New PictureBox
' Set the location and size of the PictureBox control.
picbox.Location = New System.Drawing.Point(left, top)
picbox.Size = New System.Drawing.Size(60, 60)
picbox.TabStop = False
' Set the SizeMode property to the AutoSize value.
picbox.SizeMode = PictureBoxSizeMode.AutoSize
' Set the border style to a three-dimensional border.
picbox.BorderStyle = BorderStyle.Fixed3D
' Add the PictureBox to the form.
Me.Controls.Add(picbox)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim RandomNumber As New Random
Dim WhichBox As Integer, WhichPicture As Integer
' Random a number from 0 to 10
WhichBox = RandomNumber.Next(0, 11)
' Random a number from 0 to 1
WhichPicture = RandomNumber.Next(0, 1)
PictureBox1(WhichBox).Image = Image1(WhichPicture)
End Sub
End Class
2007-05-31 05:06:46 補充:
http://hk.knowledge.yahoo.com/question/?qid=7007053002428答左你