Picturebox的ImageLocation

时间:2009-02-10 08:50:33

标签: vb.net

我在代码中遇到问题。

我的代码:

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

我收到错误:

  

imagelocation不是windows.forms.picturebox

的成员

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

谷歌:http://www.daniweb.com/forums/thread127945.html

在此编码中,只有Ctrl是Control引用而不是PictureBox。所以你需要把它投射到PictureBox参考

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