tags:

views:

282

answers:

1

I am encountering a problem in my code.

My code:

Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myPics As New DirectoryInfo("F:\Documents and Settings\Adam\My Documents\My Pictures")
        Dim r As New Random
        Dim i As Integer = r.Next(myPics.GetFiles.Length)
        Dim Pics() As FileInfo = myPics.GetFiles

        PictureBox1.ImageLocation = Pics(i).FullName
    End Sub
End Class

I get the error:

imagelocation not a member of windows.forms.picturebox

How should I fix this?

A: 

google:http://www.daniweb.com/forums/thread127945.html

In this coding just Ctrl is Control reference not a PictureBox. so You Need to Cast it to PictureBox reference

If TypeOf ctrl Is PictureBox And ctrl.Name = PictureBoxName Then
   Dim MyPictureBox as PictureBox
   MyPictureBox = ctrl

   MyPictureBox.Imagelocation = sFilename
   MyPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
End If
PoweRoy