Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 将文件夹中的图像循环到图片框中_Vb.net - Fatal编程技术网

Vb.net 将文件夹中的图像循环到图片框中

Vb.net 将文件夹中的图像循环到图片框中,vb.net,Vb.net,在这个应用程序中,我正在处理用户从一个组合框中选择一个子文件名,该子文件夹中始终有5张图片。这些图像的名称是相机输出的名称。此应用程序的目的是让用户预览小缩略图图片框中的5幅图像,然后一次选择一幅并从radiobuttons选项中重命名,按下重命名按钮后,代码将所选图像保存为所选名称 我遇到的问题是,我试图将这5幅图像加载到5个名为picPreview1、2、3、4和5的picturebox中,然后在选择单击图片框以显示较大的picturebox时,单击的图片会显示较大的图片这是将重命名的图片

在这个应用程序中,我正在处理用户从一个组合框中选择一个子文件名,该子文件夹中始终有5张图片。这些图像的名称是相机输出的名称。此应用程序的目的是让用户预览小缩略图图片框中的5幅图像,然后一次选择一幅并从radiobuttons选项中重命名,按下重命名按钮后,代码将所选图像保存为所选名称

我遇到的问题是,我试图将这5幅图像加载到5个名为picPreview1、2、3、4和5的picturebox中,然后在选择单击图片框以显示较大的picturebox时,单击的图片会显示较大的图片这是将重命名的图片

目前我有这段代码是我在线得到的,但它错误地说索引超出了数组的界限。我在网上找到的所有其他代码都是针对C的,或者根本不起作用,或者与此类似。我不知道如何修复这个错误。任何帮助都将不胜感激

代码:

完整代码:

Imports System.IO
Public Class Form1
Dim Pictype As String
Private HighlightedPictureBox As PictureBox = Nothing
Private Sub cmbPartNumber_TextChanged(sender As Object, e As EventArgs) Handles cmbPartNumber.TextChanged
    Dim FileName As String = cmbPartNumber.Text
    lblRenameAs.Text = Pictype & FileName
    Label1.Visible = True
    picPreview1.Visible = True
    picPreview2.Visible = True
    picPreview3.Visible = True
    picPreview4.Visible = True
    picPreview5.Visible = True
    Picture_Preview()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim Folder = From dir In IO.Directory.GetDirectories("\\HOMESHARE01\Public\Reference Cards\Completed Reference Cards by Part Number")
                 Select IO.Path.GetFileName(dir)

    cmbPartNumber.Items.AddRange(Folder.ToArray)
End Sub

Private Sub btnSavePic_Click(sender As Object, e As EventArgs) Handles btnSavePic.Click
    'Check if no radio button checked
    If Not (radSpindle.Checked = True Or radRotorTop.Checked = True Or radRotorBottom.Checked = True Or radDunnageFinal.Checked = True Or radDunnageLayer.Checked = True) Then
        MsgBox("Please Select Picture Type Before Renaming")
        Exit Sub
    End If
    'Check which radio button is checked
    If radSpindle.Checked = True Then
        Pictype = "PicSpindle"
    End If
    If radRotorTop.Checked = True Then
        Pictype = "PicRotorTop"
    End If
    If radRotorBottom.Checked = True Then
        Pictype = "PicRotorBottom"
    End If
    If radDunnageFinal.Checked = True Then
        Pictype = "PicDunnageFinal"
    End If
    If radDunnageLayer.Checked = True Then
        Pictype = "PicDunnageLayer"
    End If



End Sub

Public Sub Picture_Preview()
    Dim FileName As String = cmbPartNumber.Text
    Dim pics() As PictureBox = {picPreview1, picPreview2, picPreview3, picPreview4, picPreview5}
    Dim List() As String = Directory.GetFiles("\\HOMESHARE01\Public\Reference Cards\Completed Reference Cards by Part Number" & "\" & FileName, "*.jpg")

    For i As Integer = 0 To pics.Count - 1

        pics(i).Image = Image.FromFile(List(i + 5))

    Next

End Sub

Private Sub picPreview1_Click(sender As Object, e As EventArgs) Handles picPreview1.Click
    'Get the rectangle of the control and inflate it to represent the border area   
    Dim BorderBounds As Rectangle = DirectCast(sender, PictureBox).ClientRectangle
    BorderBounds.Inflate(-1, -1)

    'Use ControlPaint to draw the border.   
    'Change the Color.Red parameter to your own colour below.   
    ControlPaint.DrawBorder(DirectCast(sender, PictureBox).CreateGraphics,
                                BorderBounds,
                                Color.Red,
                                ButtonBorderStyle.Solid)

    If Not (HighlightedPictureBox Is Nothing) Then
        'Remove the border of the last PictureBox   
        HighlightedPictureBox.Invalidate()
    End If

    'Rememeber the last highlighted PictureBox   
    HighlightedPictureBox = CType(sender, PictureBox)

End Sub

Private Sub picPreview2_Click(sender As Object, e As EventArgs) Handles picPreview2.Click
    'Get the rectangle of the control and inflate it to represent the border area   
    Dim BorderBounds As Rectangle = DirectCast(sender, PictureBox).ClientRectangle
    BorderBounds.Inflate(-1, -1)

    'Use ControlPaint to draw the border.   
    'Change the Color.Red parameter to your own colour below.   
    ControlPaint.DrawBorder(DirectCast(sender, PictureBox).CreateGraphics,
                                BorderBounds,
                                Color.Red,
                                ButtonBorderStyle.Solid)

    If Not (HighlightedPictureBox Is Nothing) Then
        'Remove the border of the last PictureBox   
        HighlightedPictureBox.Invalidate()
    End If

    'Rememeber the last highlighted PictureBox   
    HighlightedPictureBox = CType(sender, PictureBox)
End Sub

Private Sub picPreview3_Click(sender As Object, e As EventArgs) Handles picPreview3.Click
    'Get the rectangle of the control and inflate it to represent the border area   
    Dim BorderBounds As Rectangle = DirectCast(sender, PictureBox).ClientRectangle
    BorderBounds.Inflate(-1, -1)

    'Use ControlPaint to draw the border.   
    'Change the Color.Red parameter to your own colour below.   
    ControlPaint.DrawBorder(DirectCast(sender, PictureBox).CreateGraphics,
                                BorderBounds,
                                Color.Red,
                                ButtonBorderStyle.Solid)

    If Not (HighlightedPictureBox Is Nothing) Then
        'Remove the border of the last PictureBox   
        HighlightedPictureBox.Invalidate()
    End If

    'Rememeber the last highlighted PictureBox   
    HighlightedPictureBox = CType(sender, PictureBox)
End Sub

Private Sub picPreview4_Click(sender As Object, e As EventArgs) Handles picPreview4.Click
    'Get the rectangle of the control and inflate it to represent the border area   
    Dim BorderBounds As Rectangle = DirectCast(sender, PictureBox).ClientRectangle
    BorderBounds.Inflate(-1, -1)

    'Use ControlPaint to draw the border.   
    'Change the Color.Red parameter to your own colour below.   
    ControlPaint.DrawBorder(DirectCast(sender, PictureBox).CreateGraphics,
                                BorderBounds,
                                Color.Red,
                                ButtonBorderStyle.Solid)

    If Not (HighlightedPictureBox Is Nothing) Then
        'Remove the border of the last PictureBox   
        HighlightedPictureBox.Invalidate()
    End If

    'Rememeber the last highlighted PictureBox   
    HighlightedPictureBox = CType(sender, PictureBox)
End Sub

Private Sub picPreview5_Click(sender As Object, e As EventArgs) Handles picPreview5.Click
    'Get the rectangle of the control and inflate it to represent the border area   
    Dim BorderBounds As Rectangle = DirectCast(sender, PictureBox).ClientRectangle
    BorderBounds.Inflate(-1, -1)

    'Use ControlPaint to draw the border.   
    'Change the Color.Red parameter to your own colour below.   
    ControlPaint.DrawBorder(DirectCast(sender, PictureBox).CreateGraphics,
                                BorderBounds,
                                Color.Red,
                                ButtonBorderStyle.Solid)

    If Not (HighlightedPictureBox Is Nothing) Then
        'Remove the border of the last PictureBox   
        HighlightedPictureBox.Invalidate()
    End If

    'Rememeber the last highlighted PictureBox   
    HighlightedPictureBox = CType(sender, PictureBox)
End Sub

Private Sub radSpindle_Click(sender As Object, e As EventArgs) Handles radSpindle.Click
    Dim FileName As String = cmbPartNumber.Text
    Pictype = "PicSpindle"
    lblRenameAs.Text = Pictype & FileName
End Sub

Private Sub radRotorTop_Click(sender As Object, e As EventArgs) Handles radRotorTop.Click
    Dim FileName As String = cmbPartNumber.Text
    Pictype = "PicRotorTop"
    lblRenameAs.Text = Pictype & FileName
End Sub

Private Sub radRotorBottom_Click(sender As Object, e As EventArgs) Handles radRotorBottom.Click
    Dim FileName As String = cmbPartNumber.Text
    Pictype = "PicRotorBottom"
    lblRenameAs.Text = Pictype & FileName
End Sub

Private Sub radDunnageLayer_Click(sender As Object, e As EventArgs) Handles radDunnageLayer.Click
    Dim FileName As String = cmbPartNumber.Text
    Pictype = "PicDunnageLayer"
    lblRenameAs.Text = Pictype & FileName
End Sub

Private Sub radDunnageFinal_Click(sender As Object, e As EventArgs) Handles radDunnageFinal.Click
    Dim FileName As String = cmbPartNumber.Text
    Pictype = "PicDunnageFinal"
    lblRenameAs.Text = Pictype & FileName
End Sub
End Class
解决了

旧代码:

For i As Integer = 0 To pics.Count - 1

    pics(i).Image = Image.FromFile(List(i + 5))

Next
固定的:

For i As Integer = 0 To pics.Count - 1

    pics(i).Image = Image.FromFile(List(i))

Next
For i As Integer = 0 To pics.Count - 1

    pics(i).Image = Image.FromFile(List(i))

Next