0

コードに問題が発生しています。

私のコード:

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のメンバーではありません

これをどのように修正すればよいですか?

4

1 に答える 1

0

グーグル: http://www.daniweb.com/forums/thread127945.html

このコーディングでは、Ctrl だけが PictureBox ではなく Control 参照です。したがって、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
于 2009-02-10T09:13:25.460 に答える