I have this program and when i want to load pictures it crashes at the form.showdialog()....???
Here it goes:
Expand|Select|Wrap|Line Numbers
- Private Sub CmbPath_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbPath.SelectedIndexChanged
- Dim Table As DataTable
- Dim i As Integer
- Dim ThumbSize As Integer = 160
- Dim ThumbNail As Image = Nothing
- FlowLayoutPanel1.Controls.Clear()
- Dim SQL As String = "SELECT fotonaam, fotomap, textveld FROM foto WHERE (fotomap = '" & Replace(CmbPath.Text, "'", "''") & "');"
- Table = SelectQuery(SQL)
- Dim ThumbPicturearr(Table.Rows.Count) As PictureBox
- Dim TextField(Table.Rows.Count) As TextBox
- Dim FlowPanel(Table.Rows.Count) As FlowLayoutPanel
- While Table.Rows.Count <> i
- Dim Photo As Image = Image.FromFile((Table.Rows(i).Item("fotomap") & "\" & Table.Rows(i).Item("fotonaam")))
- Try
- 'Determine the scale of the imahe
- Dim Scale As Single = CSng(IIf(Photo.Width > Photo.Height, ThumbSize / Photo.Width, ThumbSize / Photo.Height))
- Dim Width As Integer = CInt(Photo.Width * Scale)
- Dim Height As Integer = CInt(Photo.Height * Scale)
- ThumbNail = Photo.GetThumbnailImage(Width, Height, Nothing, New IntPtr)
- Catch ex As Exception
- MsgBox("Error creating thumbnail:" & vbCr & ex.Message)
- End Try
- Try
- ThumbPicturearr(i) = New PictureBox
- ThumbPicturearr(i).Name = "Foto" & i
- ThumbPicturearr(i).Height = 130
- ThumbPicturearr(i).Width = 160
- ThumbPicturearr(i).BackColor = Color.DarkGray
- ThumbPicturearr(i).Image = ThumbNail
- ThumbPicturearr(i).SizeMode = PictureBoxSizeMode.Zoom
- ThumbPicturearr(i).BorderStyle = BorderStyle.Fixed3D
- TextField(i) = New TextBox
- TextField(i).BackColor = Color.DarkGray
- TextField(i).ForeColor = Color.WhiteSmoke
- TextField(i).Font = New Font("Ms sans serif", 12, FontStyle.Regular, GraphicsUnit.Pixel)
- TextField(i).Size = New Size(160, 20)
- TextField(i).TextAlign = HorizontalAlignment.Center
- TextField(i).Text = Table.Rows(i).Item("textveld")
- TextField(i).BorderStyle = BorderStyle.FixedSingle
- TextField(i).Enabled = False
- TextField(i).Location = New Point(ThumbPicturearr(i).Location.X - 10, ThumbPicturearr(i).Location.Y + 5)
- FlowPanel(i) = New FlowLayoutPanel
- FlowPanel(i).Size = New Size(170, 170)
- FlowPanel(i).BackColor = Color.DarkGray
- FlowPanel(i).FlowDirection = FlowDirection.TopDown
- FlowPanel(i).Controls.Add(ThumbPicturearr(i))
- FlowPanel(i).Controls.Add(TextField(i))
- FlowLayoutPanel1.Controls.Add(FlowPanel(i))
- ThumbNail.Dispose()
- 'Increase the counter
- i = i + 1
- Catch ThumbError As Exception
- MsgBox("Error creating thumbnails for pictureboxes:" & vbCr & ThumbError.Message)
- End Try
- End While
- Table.Dispose()
- End Sub
- ' AND THEN HERE IT CRASHES AFTER I CALLED THE FORM YOU"LL SEE A PART OF IT UP HERE
- Dim EditPhoto As New Bewerk
- EditPhoto.ShowDialog()
Strange, because the form has already been loaded....
Anybody an idea?
ohyeah, when i replace "ThumbPicturearr(i).Image = ThumbNail" with "ThumbPicturearr(i).Image = Image.FromFile("c:\" & Table.rows(i).Item("fotonaam")" it's working but i don't want him to make al kind of little pictures but directly add the thumbs to the pictureboxes...
Thanks in advance!
Paul