[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

OpenFileDialog question

Posted on 2005-04-18
19
Medium Priority
?
1,285 Views
Last Modified: 2012-05-05
On my load event, I am using an OpenFileDialog to open a file.  Sometimes, unfortuantly, the file it try's to open automatically, may not be there.  I want to close the form out, if the open dialog detects the file is not there.   Again, as you can see, the filename is based on a textbox.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtFileName.Text = DocumentFileName
        txtFileType.Text = DocumentType
        OpenFileDialog1.FileName = txtFileName.Text
        OpenFileDialog1.InitialDirectory = ("v:\docmnt\" & txtFileType.Text)
        ToolTip.SetToolTip(btnOpen, "Open Image")
        ToolTip.SetToolTip(btnPrevious, "Previous Page")
        ToolTip.SetToolTip(btnNext, "Next Page")
        ToolTip.SetToolTip(cboFrameNo, "Current Page")
        curF = 0
        openImage()
    End Sub

0
Comment
Question by:chrisryhal
  • 8
  • 6
  • 3
  • +1
19 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 600 total points
ID: 13805591
Why wait, just check it before hand.

If Not System.IO.File.Exists(txtFileName.Text) Then
  Me.Close
Else
  ...  
End

Bob
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13805597
You can use the Dir() function to see if a file exists.  In your case you should probably test it before you even open the form...

If Dir(DocumentFileName) <> "" Then
    'Open the form
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 800 total points
ID: 13805610


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtFileName.Text = DocumentFileName
        txtFileType.Text = DocumentType

        if not system.io.File.Exists(v:\docmnt\" & txtFileType.Text) then me.close

        OpenFileDialog1.FileName = txtFileName.Text
        OpenFileDialog1.InitialDirectory = ("v:\docmnt\" & txtFileType.Text)
        ToolTip.SetToolTip(btnOpen, "Open Image")
        ToolTip.SetToolTip(btnPrevious, "Previous Page")
        ToolTip.SetToolTip(btnNext, "Next Page")
        ToolTip.SetToolTip(cboFrameNo, "Current Page")
        curF = 0
        openImage()
    End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 13805618
Good afternoon, Ronald :)

Bob
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13805633
Good afternoon/morning/evening, I see I'm late again :-).
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13805643
Dayton, Ohio, USA, EST -- morning.

Bob
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13805686
Tried everyone's code, and nothing seems to work.  I will paste entire code.  Once again to you Experts, thank you for your help.


=============CODE=============

Imports System.Drawing.Imaging
Imports System.IO.File

Public Class frmDocumentViewer
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents picImage As System.Windows.Forms.PictureBox
    Friend WithEvents ToolTip As System.Windows.Forms.ToolTip
    Friend WithEvents btnOpen As System.Windows.Forms.Button
    Friend WithEvents btnPrevious As System.Windows.Forms.Button
    Friend WithEvents btnNext As System.Windows.Forms.Button
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
    Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    Friend WithEvents cboFrameNo As System.Windows.Forms.ComboBox
    Friend WithEvents NotifyIcon1 As System.Windows.Forms.NotifyIcon
    Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
    Friend WithEvents btnZoom As System.Windows.Forms.MenuItem
    Friend WithEvents btnUnzoom As System.Windows.Forms.MenuItem
    Friend WithEvents txtFileName As System.Windows.Forms.TextBox
    Friend WithEvents txtFileType As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmDocumentViewer))
        Me.picImage = New System.Windows.Forms.PictureBox
        Me.ToolTip = New System.Windows.Forms.ToolTip(Me.components)
        Me.cboFrameNo = New System.Windows.Forms.ComboBox
        Me.btnOpen = New System.Windows.Forms.Button
        Me.btnPrevious = New System.Windows.Forms.Button
        Me.btnNext = New System.Windows.Forms.Button
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuItem6 = New System.Windows.Forms.MenuItem
        Me.MenuItem5 = New System.Windows.Forms.MenuItem
        Me.MenuItem7 = New System.Windows.Forms.MenuItem
        Me.MenuItem8 = New System.Windows.Forms.MenuItem
        Me.btnZoom = New System.Windows.Forms.MenuItem
        Me.btnUnzoom = New System.Windows.Forms.MenuItem
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
        Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
        Me.txtFileName = New System.Windows.Forms.TextBox
        Me.txtFileType = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'picImage
        '
        Me.picImage.BackColor = System.Drawing.Color.Gainsboro
        Me.picImage.Location = New System.Drawing.Point(8, 39)
        Me.picImage.Name = "picImage"
        Me.picImage.Size = New System.Drawing.Size(709, 636)
        Me.picImage.TabIndex = 21
        Me.picImage.TabStop = False
        '
        'ToolTip
        '
        Me.ToolTip.ShowAlways = True
        '
        'cboFrameNo
        '
        Me.cboFrameNo.Location = New System.Drawing.Point(303, 6)
        Me.cboFrameNo.Name = "cboFrameNo"
        Me.cboFrameNo.Size = New System.Drawing.Size(48, 19)
        Me.cboFrameNo.TabIndex = 34
        '
        'btnOpen
        '
        Me.btnOpen.Location = New System.Drawing.Point(21, 110)
        Me.btnOpen.Name = "btnOpen"
        Me.btnOpen.Size = New System.Drawing.Size(32, 24)
        Me.btnOpen.TabIndex = 27
        '
        'btnPrevious
        '
        Me.btnPrevious.Image = CType(resources.GetObject("btnPrevious.Image"), System.Drawing.Image)
        Me.btnPrevious.Location = New System.Drawing.Point(268, 5)
        Me.btnPrevious.Name = "btnPrevious"
        Me.btnPrevious.Size = New System.Drawing.Size(32, 24)
        Me.btnPrevious.TabIndex = 22
        '
        'btnNext
        '
        Me.btnNext.Image = CType(resources.GetObject("btnNext.Image"), System.Drawing.Image)
        Me.btnNext.Location = New System.Drawing.Point(353, 5)
        Me.btnNext.Name = "btnNext"
        Me.btnNext.Size = New System.Drawing.Size(32, 24)
        Me.btnNext.TabIndex = 21
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem5, Me.MenuItem7, Me.MenuItem8})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem6})
        Me.MenuItem1.Text = "File"
        '
        'MenuItem6
        '
        Me.MenuItem6.Index = 0
        Me.MenuItem6.Shortcut = System.Windows.Forms.Shortcut.CtrlX
        Me.MenuItem6.Text = "Exit"
        '
        'MenuItem5
        '
        Me.MenuItem5.Index = 1
        Me.MenuItem5.Text = "Page"
        '
        'MenuItem7
        '
        Me.MenuItem7.Index = 2
        Me.MenuItem7.Text = "Effects"
        '
        'MenuItem8
        '
        Me.MenuItem8.Index = 3
        Me.MenuItem8.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.btnZoom, Me.btnUnzoom})
        Me.MenuItem8.Text = "Zoom"
        '
        'btnZoom
        '
        Me.btnZoom.Index = 0
        Me.btnZoom.Text = "Zoom In"
        '
        'btnUnzoom
        '
        Me.btnUnzoom.Index = 1
        Me.btnUnzoom.Text = "Zoom Out"
        '
        'SaveFileDialog1
        '
        Me.SaveFileDialog1.FileName = "doc1"
        '
        'NotifyIcon1
        '
        Me.NotifyIcon1.Text = "NotifyIcon1"
        Me.NotifyIcon1.Visible = True
        '
        'txtFileName
        '
        Me.txtFileName.BackColor = System.Drawing.SystemColors.Info
        Me.txtFileName.Enabled = False
        Me.txtFileName.Font = New System.Drawing.Font("Batang", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtFileName.Location = New System.Drawing.Point(4, 9)
        Me.txtFileName.Name = "txtFileName"
        Me.txtFileName.Size = New System.Drawing.Size(81, 20)
        Me.txtFileName.TabIndex = 35
        Me.txtFileName.Text = ""
        '
        'txtFileType
        '
        Me.txtFileType.BackColor = System.Drawing.SystemColors.Info
        Me.txtFileType.Enabled = False
        Me.txtFileType.Font = New System.Drawing.Font("Batang", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtFileType.Location = New System.Drawing.Point(99, 9)
        Me.txtFileType.Name = "txtFileType"
        Me.txtFileType.Size = New System.Drawing.Size(95, 20)
        Me.txtFileType.TabIndex = 36
        Me.txtFileType.Text = ""
        '
        'frmDocumentViewer
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 13)
        Me.AutoScroll = True
        Me.ClientSize = New System.Drawing.Size(721, 679)
        Me.Controls.Add(Me.txtFileType)
        Me.Controls.Add(Me.txtFileName)
        Me.Controls.Add(Me.picImage)
        Me.Controls.Add(Me.btnNext)
        Me.Controls.Add(Me.cboFrameNo)
        Me.Controls.Add(Me.btnPrevious)
        Me.Controls.Add(Me.btnOpen)
        Me.Font = New System.Drawing.Font("Batang", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Menu = Me.MainMenu1
        Me.Name = "frmDocumentViewer"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Document Tracker .NET - View Document"
        Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim curF As Integer
    Dim finishX, finishY As Integer
    Dim startX, startY As Integer
    Dim up, down As Point
    Dim strFilePath As String
    Dim strPath As String
    Dim strFileName As String
    Dim g As Graphics
    Dim totFrame As Integer
    Dim frameCount As String
    Dim pageNo As Integer
    Dim objfile As System.IO.File
    Dim objImage As System.Drawing.Image
    Dim ifSaved As Boolean = False
    Dim isDelete As Boolean = True
    Dim isEdit As Boolean = False

    'Loads the .Tiff file and saves every frame as a seperate .tiff file
    Private Sub loadImage(ByVal strFilePath As String)
        picBoxSize()
        ifSaved = False
        cboFrameNo.Items.Clear()

        'Changed the cursor to waitCursor
        Me.Cursor = System.Windows.Forms.Cursors.WaitCursor

        'Sets the tiff file as an image object.
        objImage = objImage.FromFile(strFilePath)
        Dim objGuid As Guid = (objImage.FrameDimensionsList(0))
        Dim objDimension As System.Drawing.Imaging.FrameDimension = New System.Drawing.Imaging.FrameDimension(objGuid)

        'Gets the total number of frames in the .tiff file
        totFrame = objImage.GetFrameCount(objDimension)

        'Adds number of frames to the combo box for displaying purposes.
        Dim i As Integer
        For i = 0 To totFrame - 1
            cboFrameNo.Items.Add(i)
        Next
        cboFrameNo.Items.IndexOf(1)

        'Sets the temporary folder to "C:\temp\"
        strPath = "c:\temp\"

        'Saves every frame as a seperate file.
        Dim z As Integer
        z = 0
        curF = 0
        For z = 0 To (totFrame - 1)
            objImage.SelectActiveFrame(objDimension, curF)
            objImage.Save(strPath & curF & ".tif", Imaging.ImageFormat.Tiff)
            curF = curF + 1
        Next
        curF = 0

        'Displayes the frames
        DisplayFrame()
        Me.Cursor = System.Windows.Forms.Cursors.Default
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtFileName.Text = DocumentFileName
        txtFileType.Text = DocumentType
            OpenFileDialog1.FileName = txtFileName.Text
            OpenFileDialog1.InitialDirectory = ("v:\docmnt\" & txtFileType.Text)
            ToolTip.SetToolTip(btnOpen, "Open Image")
            ToolTip.SetToolTip(btnPrevious, "Previous Page")
            ToolTip.SetToolTip(btnNext, "Next Page")
            ToolTip.SetToolTip(cboFrameNo, "Current Page")
            curF = 0
            openImage()
    End Sub

    'on click displays the next page
    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If checkPath() = True Then
            btnPrevious.Enabled = True
            If isEdit = True Then
                isDelete = False
            Else
                isDelete = True
            End If

            nextFrame()
            DisplayFrame()
        Else
            Exit Sub
        End If

    End Sub

    'Gets the next frame number
    Private Sub nextFrame()
        If curF = totFrame - 1 Then
            btnNext.Enabled = False
            Exit Sub
        Else
            curF = curF + 1
        End If
    End Sub

    'on click displays the previous frame
    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If checkPath() = True Then
            btnNext.Enabled = True
            If isEdit = True Then
                isDelete = False
            Else
                isDelete = True
            End If

            previousFrame()
            DisplayFrame()
        Else
            Exit Sub
        End If
    End Sub

    'gets the previous frame number
    Public Sub previousFrame()
        If curF = 0 Then
            btnPrevious.Enabled = False
            Exit Sub
        Else
            curF = curF - 1
        End If
    End Sub

    Private Sub DisplayFrame()
        Select Case isDelete
            Case True
                Dim objImage As System.Drawing.Image = objImage.FromFile(strFilePath)
            Case False
                Dim objImage As System.Drawing.Image = objImage.FromFile(strPath & curF & ".tif")
        End Select

        Dim objGuid As Guid = (objImage.FrameDimensionsList(0))
        Dim objDimension As System.Drawing.Imaging.FrameDimension = New System.Drawing.Imaging.FrameDimension(objGuid)
        objImage.SelectActiveFrame(objDimension, curF)
        picImage.Image = objImage
        picImage.SizeMode = PictureBoxSizeMode.StretchImage
        cboFrameNo.Text = curF
    End Sub
    Private Sub cboFrameNo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFrameNo.SelectedIndexChanged
        curF = cboFrameNo.Text
        If curF = totFrame - 1 Then
            btnNext.Enabled = True
            Exit Sub
        Else
            DisplayFrame()
        End If
    End Sub
    Private Sub actualSize()
        picImage.Width = objImage.Width
        picImage.Height = objImage.Height
    End Sub

    Private Sub picBoxSize()
        picImage.Width = 600
        picImage.Height = 640
    End Sub

    'on mouse down gets the x,y position of the mouse
    Public Sub mDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picImage.MouseDown
        'Checks to see if the cursor is cross
        If Me.Cursor Is System.Windows.Forms.Cursors.Cross Then
            'Checks if left mouse button in clicked
            If e.Button <> MouseButtons.Left Then
                Exit Sub
            Else
                'Gets starting position of the mouse
                startX = e.X
                startY = e.Y
                down = New Point(startX, startY)
            End If
        End If
    End Sub

    'on mouse up gets the x,y position of the mouse and draws user defined
    'rectangle. Then saves the page as curF & "s" & ".tif"
    Private Sub mUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picImage.MouseUp
        'Checks to see if the cursor is cross
        If Me.Cursor Is System.Windows.Forms.Cursors.Cross Then
            Dim img As Drawing.Image
            'sets the current page as image.
            img = Image.FromFile(strPath & curF & ".tif")

            Dim objBmp As New Bitmap(img, img.Width, img.Height)
            Dim objNewBmp As New Bitmap(objBmp.Width, objBmp.Height, Imaging.PixelFormat.Format16bppRgb555)

            Dim g As Graphics
            g = Graphics.FromImage(objNewBmp)
            'Creats a duplicate image file as bitmap format
            Dim rect As Rectangle
            With rect
                .Width = img.Width
                .Height = img.Height
                .X = 0
                .Y = 0
            End With

            g.DrawImage(img, rect)

            Dim DrawRect As Rectangle
            'Sets the position of the mouse
            finishX = e.X
            finishY = e.Y

            up = New Point(finishX, finishY)
            'Sets the value of rectangle, x, y, width, height position
            DrawRect = New Rectangle(Math.Min(up.X, down.X), Math.Min(up.Y, down.Y), Math.Abs(up.X - down.X), Math.Abs(up.Y - down.Y))

            Dim b As SolidBrush = New SolidBrush(Color.White)
            g.FillRectangle(b, DrawRect)

            'Creates an rectagnle on the picture box for visual.
            g = picImage.CreateGraphics
            g.FillRectangle(b, DrawRect)

            If MsgBox("Do you want to save the change?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                objNewBmp.Save(strPath & curF & "s" & ".tif", Imaging.ImageFormat.Tiff)
                g.Dispose()
                objNewBmp.Dispose()
            Else
                g.Dispose()
                objNewBmp.Dispose()
            End If
        End If
    End Sub


    ' Opens an image to edit
    Private Sub openImage()
        If strFilePath = "" Then
            cboFrameNo.Items.Clear()
            OpenFileDialog1.ShowDialog()
            strFilePath = OpenFileDialog1.FileName.ToString
            If strFilePath = "" Then
                MsgBox("Please select an image")
                OpenFileDialog1.ShowDialog()
            Else
                loadImage(strFilePath)
            End If
        Else
            MsgBox("Please close the current image", MsgBoxStyle.Information)
        End If
    End Sub

    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
        If strFilePath = "" Then
            End
        Else
            closeFile()
            End
        End If
    End Sub



    'Saves the edited image
    Private Sub saveImage()
        If checkPath() = True Then

            SaveFileDialog1.AddExtension = True
            SaveFileDialog1.ShowDialog()
            strFileName = SaveFileDialog1.FileName()
            strFileName = strFileName & ".tif"

            Me.Cursor = System.Windows.Forms.Cursors.WaitCursor

            'Deletes the original edited pages. For example page 0.tif was edited
            'and saved as 0s.tif. Now delete the 0.tif in order rename the
            '0s.tif file to 0.tif. Then we can package all the page numbers back to
            'one .tiff file

            Dim z As Integer
            Dim editPageCount As Integer


            For z = 0 To editPageCount
                If z = editPageCount Then
                    Exit For
                End If
                Dim strEditedPage As String

                Try
                    If objfile.Exists(strPath & strEditedPage & ".tif") Then
                        objfile.Delete(strPath & strEditedPage & ".tif")
                        objfile.Move(strPath & strEditedPage & "s" & ".tif", strPath & strEditedPage & ".tif")
                    End If
                Catch ex As Exception

                End Try
            Next

            Dim saveTif As Bitmap = New Bitmap(strPath & curF & ".tif")

            Dim myImageCodecInfo As ImageCodecInfo
            Dim myEncoder As Encoder
            Dim myEncoderParameter As EncoderParameter
            Dim myEncoderParameters As EncoderParameters

            'Get an ImageCodecInfo object that represents the TIFF codec.
            myImageCodecInfo = GetEncoderInfo("image/tiff")

            'Create an Encoder object based on the GUID
            'for the SaveFlag parameter category.
            myEncoder = Encoder.SaveFlag
            'Create an EncoderParameters object.
            'An EncoderParameters object has an array of EncoderParameter
            'objects. In this case, there is only one
            'EncoderParameter object in the array.
            myEncoderParameters = New EncoderParameters(1)

            myEncoderParameter = New EncoderParameter(myEncoder, CLng(EncoderValue.MultiFrame))
            myEncoderParameters.Param(0) = myEncoderParameter
            saveTif.Save(strFileName, myImageCodecInfo, myEncoderParameters)

            Dim i As Integer
            cboFrameNo.Items.RemoveAt(0)
            frameCount = cboFrameNo.Items.Count
            'Removes the page 1 from the combo box. otherwise first page will be
            'saved twice.
            Try
                For i = 0 To frameCount

                    pageNo = cboFrameNo.Items.Item(i)

                    If objfile.Exists(strPath & pageNo & ".tif") Then
                        Dim saveFrame As Bitmap = New Bitmap(strPath & pageNo & ".tif")

                        myEncoderParameter = New EncoderParameter(myEncoder, CLng(EncoderValue.FrameDimensionPage))
                        myEncoderParameters.Param(0) = myEncoderParameter
                        saveTif.SaveAdd(saveFrame, myEncoderParameters)
                        saveFrame.Dispose()
                    End If
                Next
            Catch ex As Exception
            End Try

            saveTif.Dispose()
            Me.Cursor = System.Windows.Forms.Cursors.Default

            MsgBox("File saved as" & strFileName)
            ifSaved = True

            If MsgBox("Do you want to close this image?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                closeFile()
            Else
                'Changes the file to newly saved file name and loads the saved file.
                strFilePath = strFileName
                isDelete = True
                loadImage(strFileName)
            End If
        Else
            Exit Sub
        End If
    End Sub
    Private Shared Function GetEncoderInfo(ByVal mimeType As [String]) As ImageCodecInfo
        Dim i As Integer
        Dim encoders() As ImageCodecInfo
        encoders = ImageCodecInfo.GetImageEncoders()

        For i = 0 To (encoders.Length - 1)
            If (encoders(i).MimeType = mimeType) Then
                Return encoders(i)
            End If
        Next i
    End Function
    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        closeFile()
    End Sub
    'Closes the open image file
    Private Sub closeFile()
        If checkPath() = True Then
            If ifSaved = True Then
                picImage.Image = Nothing
                isDelete = True
                strFilePath = ""
                cboFrameNo.Items.Clear()

            Else
                If MsgBox("Do you want to close the image without saving?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                    picImage.Image = Nothing
                    objImage.Dispose()

                    isDelete = True
                    strFilePath = ""
                    cboFrameNo.Items.Clear()
                Else
                    Exit Sub
                End If
            End If
        Else
            Exit Sub
        End If
    End Sub
    'Checks if there is an image loaded for editing.
    Private Function checkPath() As Boolean
        If strFilePath = "" Then
            MsgBox("Select an image to edit", MsgBoxStyle.Information)
            checkPath = False
            Exit Function
        Else
            checkPath = True
        End If
    End Function
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        closeFile()
    End Sub
    Private Sub btnNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If checkPath() = True Then
            Me.Cursor = System.Windows.Forms.Cursors.Default
            picBoxSize()
        End If
    End Sub
    Private Sub btnActual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If checkPath() = True Then
            actualSize()
        End If
    End Sub
    Private Sub btnUnzoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnzoom.Click
        If checkPath() = True Then
            picImage.Width = CInt(picImage.Width / 1.25)
            picImage.Height = CInt(picImage.Height / 1.25)
        Else
            Exit Sub
        End If
    End Sub
    Private Sub btnZoom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoom.Click
        If checkPath() = True Then
            picImage.Width = CInt(picImage.Width * 1.25)
            picImage.Height = CInt(picImage.Height * 1.25)
        Else
            Exit Sub
        End If
    End Sub
End Class

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13805701
I don't see where the Form_Load has changed any.

Bob
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13805709
No, I pasted the original problem code.  I tried what everyone said though with the IF Statements, IF NOT Statementsl, and such
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 600 total points
ID: 13805717
Why even load the form if the file does not exist?
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13805725
Well, the form that loads this form, is a datagrid that the user doubleclicks on, to then launch this page.  If there is a way to check if the file exists prior, please give me an idea
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13805762
Guess I could do something like PING it first, but I am unsure how to do that even with VB.NET code
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13805766
Yes, you can use the System.IO.File.Exists before the form is opened, in whatever procedure shows the form.

Bob
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13805785
Ok, I will play around with some of your methods, and get back with you here shortly
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13806050
Got the check to work, on DataGrid DoubleClick event:

    Private Sub DocumentDataGrid_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DocumentDatagrid.DoubleClick
        Dim pt As System.Drawing.Point = DocumentDatagrid.PointToClient(Cursor.Position)
        Dim hti As DataGrid.HitTestInfo = DocumentDatagrid.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.RowHeader Then
            txtFileName.Text = CType(DocumentData.Tables(0).DefaultView.Item(hti.Row).Item("FileName"), String)
            txtDocType.Text = CType(DocumentData.Tables(0).DefaultView.Item(hti.Row).Item("FileType"), String)
        End If
        DocumentFileName = txtFileName.Text 'Module Call
        DocumentType = txtDocType.Text

        If Not System.IO.File.Exists("v:\docmnt\" & txtDocType.Text & "\" & txtFileName.Text) Then
            Dim r As DialogResult
            r = MsgBox("File Is No Longer Available.  Please Contact IT Dept If You Feel This Is In Error", MsgBoxStyle.OKOnly, "Success..")
        Else
            Dim frmDocumentViewer As New frmDocumentViewer
            frmDocumentViewer.ShowDialog()
        End If
    End Sub
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13806074
I split the points up as best as I could, because you all helped me out, and all your answers were right, including the idea "Why Even Open The Form, If File Doesn't Exist"

Thanks again,
CR
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13806100
I think I got too much points for this, TheLearnedOne gave the same answer as me, and he was first :-)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13806105
No problem, Ronald, happy to share :)

Bob
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 13806107
Thats true, can we get it reversed???
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question