visual basic ile ilgili bir soru

Kodla Büyü

duce

Aktif Üye
Mesajlar
166
soru visual basic 2008 de picturebox ile ilgili.
şimdi 5 tane picturebox ımız var. rastgele ürettiğimiz sayı ile hangi picturebox ta resim göstereceğimizi belileyeceğiz.
Yani butona basıldığında 1 ile 5 arasında rastgele bir sayı üreteceğiz ve bu ürettiğimiz sayıdaki picturebox a resim ekleyeceğiz.
İnşallah anlatabilmişimdir.
 
vb.net

Dim sayi As Integer
Randomize()
sayi = Rnd() * 4 + 1
Label1.Text = sayi

PictureBox1.Image = Nothing
PictureBox2.Image = Nothing
PictureBox3.Image = Nothing
PictureBox4.Image = Nothing
PictureBox5.Image = Nothing
Select Case sayi
Case 1 : PictureBox1.Image = Image.FromFile("aaa.jpg")
Case 2 : PictureBox2.Image = Image.FromFile("aaa.jpg")
Case 3 : PictureBox3.Image = Image.FromFile("aaa.jpg")
Case 4 : PictureBox4.Image = Image.FromFile("aaa.jpg")
Case 5 : PictureBox4.Image = Image.FromFile("aaa.jpg")
End Select

aaa.jpg resmi debug klasöründe olacak.
kolay gelsin.
 
Kod:
Public Class Form1
    Dim rand As New Random()
    Dim sayi
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        PictureBox1.Image = Nothing
        PictureBox2.Image = Nothing
        PictureBox3.Image = Nothing
        PictureBox4.Image = Nothing
        PictureBox5.Image = Nothing

        sayi = rand.Next(1, 6)
        If sayi = 1 Then
            PictureBox1.ImageLocation = "c:/a.jpg"
        End If
        If sayi = 2 Then
            PictureBox2.ImageLocation = "c:/a.jpg"
        End If
        If sayi = 3 Then
            PictureBox3.ImageLocation = "c:/a.jpg"
        End If
        If sayi = 4 Then
            PictureBox4.ImageLocation = "c:/a.jpg"
        End If
        If sayi = 5 Then
            PictureBox5.ImageLocation = "c:/a.jpg"
        End If

    End Sub
End Class
 

Ekli dosyalar

  • screen cap.jpg
    screen cap.jpg
    173.5 KB · Görüntüleme: 622
Geri
Üst