tags:

views:

35

answers:

2

I would like to implement an open file dialog or file browser that additionally offers a "Preview" button to play the currently selected sound file (wave format in particular, other formats are not necessary for this application).

  • I could create my own form with various controls such as a treeview and listbox to show the folders and files, but I think I would be reinventing the wheel, or if nothing else going to a lot of work for something very simple. Do you recommend doing this?
  • Can I modify (inherit) the existing OpenFileDialog and add the sound-playing button to it somehow?
  • Is there some free library of custom file pickers that could be utilized? (Provided that the license allows inclusion in a commercial sense.)
+1  A: 

Regarding point 2, I had thought the OpenFileDialog (or SaveFileDialog) weren't extendable in any way - they are provided by the OS.

But, it turns out they could be:

The first one looks like what you're wanting to achieve.

Good luck.

Reddog
Actually the second, since this is Winforms rather than WPF. Looks very promising, though! Thanks for the link, I'll take a look.
JYelton
You can use WPF in a WinForms app if you've already got the Framework 3+ dependency... Then maybe you can sex it up a little too... :)
Reddog
I have these plans to learn WPF eventually... Unfortunately for this app I don't have the time to upgrade my *noobishness!* :)
JYelton
+1  A: 

Before you get carried away hacking the dialog, consider a simple solution first that leverages the FileOk event. Create a form named, say, frmPreview. Give it a constructor that takes a string. You'll need a Cancel and an OK button and code to play the file.

Display that form like this:

        var dlg = new OpenFileDialog();
        // Set other dlg properties...
        dlg.FileOk += (s, cancel) => {
            using (var prev = new frmPreview(dlg.FileName)) {
                if (prev.ShowDialog() != DialogResult.OK) cancel.Cancel = true;
            }
        };
        if (dlg.ShowDialog(this) == DialogResult.OK) {
            // use the file
            //...
        }

Now, whenever the user clicks Open, your preview form shows up. The user can click Cancel and pick another file from the dialog.

Hans Passant
This is a very viable solution also, I will give it a try in my testing.
JYelton
Agreed that hacking the dialog is not optimal, however, as far as UX goes, nor is a popup from a popup...
Reddog