2011-07-26 5 views
1

로드하는 동안 이미지를 저장하는 백업 폴더가 있습니다. 그래서 체크 된 목록 상자에서 삭제할 때 백업 폴더에서 이미지를 삭제해야합니다.vb.net에서 파일 이름을 사용하여 폴더에서 이미지를 삭제

어떻게하면됩니까?

If CheckedListBox1.Items.Count = 0 Then 
     MsgBox("Please load the images", MsgBoxStyle.Critical) 
    Else 
     If Thumbcontrol1.SelectedThumbnail Is Nothing Then 
      MsgBox("Please select the thumbnail to remove", MsgBoxStyle.Information) 
     Else 
      CheckedListBox1.Items.Remove(CheckedListBox1.SelectedItem) 
      Thumbcontrol1.RemoveSelectedThumbnail() 

      If CheckedListBox1.Items.Count > 0 Then 
       CheckedListBox1.SelectedIndex = CInt(index) 
      End If 
      If CheckedListBox1.Items.Count = 0 Then 
       Thumbcontrol1.BackgroundImage = My.Resources.backimage 
       frmDisplay.GCanvas1.Image = Nothing 
      End If 
     End If 
    End If 

답변

2

당신은 방법에 파일 경로를 제공하여, 파일을 삭제하는 System.IO.File 클래스의 방법을 사용할 수 있습니다.

System.IO.File.Delete("path\to\file") 
0
Imports System.Data.OleDb 
Public Class Form2 
    Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\dv.accdb;") 
    Dim cm As New OleDbCommand 

    Dim bytImage() As Byte 


    Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click 
     Dim dialog As New OpenFileDialog() 
     dialog.Title = "Browse Picture" 
     dialog.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG" 
     If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then 
      PictureBox1.Image = Image.FromFile(dialog.FileName) 
     End If 
    End Sub 

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click 
     Try 
      Dim ms As New System.IO.MemoryStream 
      Dim bmpImage As New Bitmap(PictureBox1.Image) 

      bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) 
      bytImage = ms.ToArray() 
      ms.Close() 
     Catch ex As Exception 
      MsgBox(ex.Message) 
     End Try 
     cn.Open() 
     cm.Connection = cn 
     cm.CommandType = CommandType.Text 
     cm.CommandText = "INSERT INTO `pic1` (pic) VALUES (@image)" 
     cm.Parameters.AddWithValue("@image", bytImage) 
     cm.ExecuteNonQuery() 
     cn.Close() 
     MsgBox("Image Saved.") 
    End Sub 
+5

이 당신의 예제 코드는 질문에 대답에 기여하는 것에 정성 들여없이 적절한 답변을하지 않습니다 – DomTomCat

관련 문제