首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb有关问题?

2012-02-29 
vb问题??PublicClassForm2InheritsSystem.Windows.Forms.FormDimcommentary(4)AsStringDimFilename(4)AsSt

vb问题??
Public   Class   Form2
        Inherits   System.Windows.Forms.Form
        Dim   commentary(4)   As   String
        Dim   Filename(4)   As   String
        Dim   Currentphoto   As   Integer

        Private   Sub   loadphoto()
                PictureBox1.Image   =   Image.FromFile(Filename(Currentphoto))
//在2005下编译上边的那句那错了?
                Label1.Text   =   commentary(Currentphoto)
        End   Sub

        Private   Sub   Button4_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button4.Click
                Currentphoto   =   4
                loadphoto()
        End   Sub
        Private   Sub   Button3_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button3.Click
                Currentphoto   +=   1
                If   Currentphoto   >   4   Then   Currentphoto   =   1
                loadphoto()
        End   Sub
        Private   Sub   Button2_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button2.Click
                Currentphoto   -=   1
                If   Currentphoto   <   1   Then   Currentphoto   =   4
                loadphoto()
        End   Sub
        Private   Sub   Button1_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button1.Click
                Currentphoto   =   1
                loadphoto()
        End   Sub
        Private   Sub   Form2_Load(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   MyBase.Load
                commentary(1)   =   "nihao1 "
                commentary(2)   =   "nihao2 "
                commentary(3)   =   "nihao3 "
                commentary(4)   =   "nihao4 "
                Filename(1)   =   Application.StartupPath   &   "E:\IMG_0674.JPG "
                Filename(2)   =   Application.StartupPath   &   "E:\IMG_0675.JPG "
                Filename(3)   =   Application.StartupPath   &   "E:\IMG_0676.JPG "


                Filename(4)   =   Application.StartupPath   &   "E:\IMG_0677.JPG "
                Currentphoto   =   1
                Call   loadphoto()
        End   Sub
End   Class

[解决办法]
Filename(1) = Application.StartupPath & "E:\IMG_0674.JPG "

Application.StartupPath 是您EXE文件的存放路径,您在后面又加上一个绝对路径,这个可能就不对了,所以Image.FileFrom方法就不能取道正确的文件了。
[解决办法]
Application.StartupPath

就是您正在写的这个程序的EXE文件的存放路径。
[解决办法]
如果您的图片是 "E:\IMG_0674.JPG ",那么把Application.StartupPath去掉就好了。

热点排行