Home Image-Pro Automation (Macros, Apps, Reports)
Options

How to select a file or directory path in your App

It is often useful in applications to be able to provide simple buttons that will prompt the user to select either a file or a directory and then perform specific actions using the values returned. The following discussion explains how to achieve this in the Project Workbench and illustrates the technique with a couple of buttons, "Save" and "Browse". Some commands that require either a file or directory path are already provided in Premier to handle this interaction (the Save command for instance), but this approach can be used for any other action for which a pre-built API does not exist.

The illustration below shows the use of a "SaveFileDialog" and "FolderBrowserDialog" components which can be dropped on the App surface like any other control and will then appear under the App itself, thus providing a way to edit their properties, like the title or the initial directory.

image

Once the components are there it is possible to create a couple of buttons that will use them to prompt the user. The code for each button is edited with a double-click, and can both initialize some component properties if desired, and use the resulting selection once the dialog is validated.

    Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click
        If saveFileDialog1.ShowDialog()= system.Windows.Forms.DialogResult.OK Then
            MsgBox(saveFileDialog1.FileName)
        End If
    End Sub

    Private Sub button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button2.Click
        If folderBrowserDialog1.ShowDialog()= system.Windows.Forms.DialogResult.OK Then
            MsgBox(folderBrowserDialog1.SelectedPath)
        End If
    End Sub
Sign In or Register to comment.