i have this code below to remove dynamically created image boxes from a form and then kill the file and refresh the image list and repopulate image boxs but its not working .... keeps telling me that the files are open/readonly
is there a quick way to close these images ?
many thanks
illskills
VB Code:
Dim sCurrFile As String sCurrFile = cmbDesigns.Text If sCurrFile.Trim = "" Then Exit Sub End If If MessageBox.Show("Remove from gallery?", "Remove image.", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) = DialogResult.OK Then Dim i As Integer = 0 removeanother: For i = 0 To Me.Controls.Count - 1 If Me.Controls(i).GetType.ToString = "System.Windows.Forms.PictureBox" Then If Me.Controls(i).Name <> "pbPreview1" Then If Me.Controls(i).Name <> "pbPrevTes" Then Dim oControl As PictureBox oControl = CType(Me.Controls(i), PictureBox) oControl.Image = Nothing Me.Controls.Remove(oControl) GoTo removeanother End If End If End If Next i pbPreview1.Image = Nothing pbPrevTes.Image = Nothing On Error Resume Next Kill(Application.StartupPath & "\Gallery\KeyPatterns\" & sCurrFile.Trim) On Error GoTo 0 Dim sFirstFile As String = "" sFirstFile = PopulateItems() cmbDesigns.Text = sFirstFile If sFirstFile <> "" Then Dim oBMP As New Bitmap(Application.StartupPath & "\Gallery\KeyPatterns\" & Trim(sFirstFile)) 'oBMP = ResizeImage(oBMP, 320, 600) UpdateImage(oBMP) End If End If




Reply With Quote