В этом приложении я работаю над тем, что пользователь выбирает имя подфайла из выпадающего списка, и внутри этой подпапки есть (всегда) 5 изображений. Имена этих изображений - это то, что когда-либо выдает их камера. Цель этого приложения - позволить пользователю просмотреть 5 изображений в маленьких миниатюрных фотобарабанах, затем выбрать по одному и переименовать из параметров радиообмена, после нажатия кнопки «переименовать» код должен сохранить выбранное изображение в качестве выбранного имени.Зацикливание изображений из папки в ящики изображений
У меня возникли проблемы с этим. Я пытаюсь загрузить эти 5 изображений в 5 картинных ящиков с именем picPreview1,2,3,4 и 5, а затем при выборе (щелчке) окна с изображением, чтобы увеличить изображение нажмите больше (это изображение, которое будет переименовано).
В настоящее время у меня есть этот код, который я получил в сети, но он ошибается, говоря Index was outside the bounds of the array.
. Все остальные коды, которые я нашел онлайн, для C# или вообще не работают или похожи на это. Я не уверен, как исправить эту ошибку. Любая помощь будет оценена по достоинству.
Код:
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
Полный код:
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