Select to view content in your preferred language

Esri version of FolderBrowserDialog

768
3
04-10-2023 02:28 PM
StevenCorpus
Emerging Contributor

I have a part in my code that requires the user to select a folder. I've been using the microsoft dialog FolderBrowserDialog do this. It works fine except that the dialog isn't dark when the ArcGIS Pro user has set Pro to dark theme. 

Is there an Esri equivelent to the FolderBrowserDialog, or is there a way that I can configure an Esri dialog to do the same task?

 

Thanks

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

The OpenItemDialog is what you're looking for. You can set the BrowseProjectFilter to a folder. The full list of filters is here. This snippet shows how to use it.

0 Kudos
CharlesMacleod
Esri Regular Contributor

Set the dialog filter to ItemFilters.Folders. A FolderConnectionProjectItem will be returned. 

 

 var home = Project.Current.HomeFolderPath;
 var opn_dlg = new OpenItemDialog();
 opn_dlg.Title = "Select a Folder";
 opn_dlg.InitialLocation = home;
 opn_dlg.MultiSelect = false;//or true, whichever
 opn_dlg.Filter = ArcGIS.Desktop.Catalog.ItemFilters.Folders;//select folders only

 bool? ok = opn_dlg.ShowDialog();
 if (ok == true) {
   var folder = opn_dlg.Items[0] as FolderConnectionProjectItem;
   var path = folder.Path;
   //TODO - use folder selection
 }
 

 

RichardDaniels
Honored Contributor

To control the color like you describe  you may need to build your own FoldierLocator dialog and use the showdialog()  command to open it. If you create your own form there is a BackColor property you can use. You would call the following Subroutined after instantiating the form but Before showing it. In this example I've stored my desired Form color in the myAppColor environment variable.  I've used 'Named' colors as available from the SystemColors collection. 

 

 

    Sub setControlColor(ByRef theForm As System.Windows.Forms.Form)
        Dim theControl As Control
        Try
            theForm.BackColor = My.Settings.Default.myAppColor
        Catch eX As Exception
            'unable to get the color
            theForm.BackColor = SystemColors.Control
        End Try

        For Each theControl In theForm.Controls
            If theControl.GetType Is GetType(TextBox) Then
                'do nothing since we want white backgrounds in our text box
            Else
                theControl.BackColor = My.Settings.Default.myAppColor
                theControl.Invalidate()
            End If
            If theControl.GetType Is GetType(System.Windows.Forms.Button) Then
                Dim theButton As System.Windows.Forms.Button
                theButton = theControl
                theButton.UseVisualStyleBackColor = False
            End If
        Next
        theForm.Refresh()
    End Sub

 

 

 

0 Kudos