单击保存按钮

时间:2018-01-19 02:57:50

标签: .net database vb.net save openfiledialog

当我点击浏览图片时,下面的代码工作正常,但问题是当图像浏览时,图像在项目文件夹上移动。但是我点击保存记录时,时间图像在项目文件夹上移动,所以任何人都可以帮我区分下面的代码。

 Dim SAVE_PATH As String = Application.StartupPath & "\Database\Image"
 Dim fso = My.Computer.FileSystem
 Dim imgName As String


    Private Sub add_design_image_button_Click(sender As Object, e As EventArgs) Handles add_design_image_button.Click

        With OpenFileDialog1
            If Not fso.DirectoryExists(SAVE_PATH) Then
                Try
                    fso.CreateDirectory(SAVE_PATH)
                Catch ex As Exception
                    MessageBox.Show("Unable to create folder '" & SAVE_PATH.ToLower & _
                                "'.  Images will be saved in '" & Application.StartupPath.ToLower & _
                                "'.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    SAVE_PATH = Application.StartupPath
                End Try
            End If

                .InitialDirectory = SAVE_PATH
                .Filter = "All Graphic Files|*.bmp;*.gif;*.jpg;*.jpeg;*.png;|" & _
            "Graphic Interchange Format (*.gif)|*.gif|" & _
            "Portable Network Graphics (*.png)|*.png|" & _
            "JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg|" & _
            "Windows Bitmap (*.bmp)|*.bmp"
                .FilterIndex = 1
                .FileName = ""
                If .ShowDialog = Windows.Forms.DialogResult.OK Then
                    imgName = OpenFileDialog1.FileName

                    Dim newimg As New Bitmap(imgName)

                    design_picturebox.SizeMode = PictureBoxSizeMode.StretchImage
                    design_picturebox.Image = DirectCast(newimg, Image)

                    If .FileName.ToUpper = (SAVE_PATH & "\" & fso.GetName(.FileName)).ToUpper Then
                        MessageBox.Show("The file '" & fso.GetName(.FileName).ToLower & "' cannot be copied onto itself.", _
                                        Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
                        Exit Sub
                    ElseIf fso.FileExists(SAVE_PATH & "\" & fso.GetName(.FileName)) Then
                        Dim Response As DialogResult
                        Response = MessageBox.Show("The file '" & fso.GetName(.FileName).ToLower & "' already exist in the destination folder '" & _
                                                   SAVE_PATH & "'" & vbCrLf & vbCrLf & "Do you want to overwite it?", Text, MessageBoxButtons.YesNo, _
                                                   MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

                        If Response = Windows.Forms.DialogResult.No Then Exit Sub
                    End If
                    Try
                        fso.CopyFile(.FileName, SAVE_PATH & "\" & fso.GetName(.FileName), True)
                    Catch ex As Exception
                        MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                End If
        End With


    End Sub

感谢。

0 个答案:

没有答案