programming4us
programming4us
DESKTOP

Working with the windows 7 common file dialogs (part 1)

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
12/12/2011 5:43:55 PM
The common file dialogs, such as File Open and File Save, have been around since the earliest versions of Windows. The first versions of these dialog boxes were a bit clumsy and often didn't offer much flexibility. Configuring the dialog boxes could also be confusing or at least difficult, but with each version of Windows, Microsoft has sought to solve the most perplexing common file dialog problems. Windows 7 is no exception to the rule. The following sections describe the latest version of the common file dialogs and demonstrate how you can access them from your application using the Common File Dialogs example.

1. Considering the Common File Dialog Controls

The Microsoft.WindowsAPICodePack.Dialogs.Controls namespace contains a number of controls you can use to interact with the common file dialogs. In most cases, you won't need to add to or subtract from the default configuration, but it's good to know that you have these controls available. The following list provides a quick overview of these controls:

  • CommonFileDialogButton: Creates a pushbutton control.

  • CommonFileDialogCheckBox: Creates a checkbox control.

  • CommonFileDialogComboBox: Creates a combo box control. Every combo box must have at least one CommonFileDialogComboBoxItem object in it.

  • CommonFileDialogComboBoxItem: Defines one ComboBoxItem for inclusion in a CommonFileDialogComboBox control.

  • CommonFileDialogGroupBox: Creates a group box that can contain other controls. Grouping performs an important function both in the visual sense (putting like functionality together) and also in application functionality (such as radio buttons).

  • CommonFileDialogLabel: Creates a label control.

  • CommonFileDialogMenu: Creates a menu control. Each menu control must have at least one CommonFileDialogMenuItem object in it.

  • CommonFileDialogMenuItem: Defines an individual menu item within a CommonFileDialogMenu object.

  • CommonFileDialogSeparator: Provides a separator between menu items. You use this control to create menu item groupings.

  • CommonFileDialogRadioButtonList: Creates a radio button list. Each radio button list must have at least one CommonFileDialogRadioButtonListItem object in it.

  • CommonFileDialogRadioButtonListItem: Defines an individual radio button within a CommonFileDialogRadioButtonList object.

  • CommonFileDialogTextBox: Creates a textbox control.

The interesting part about the new Windows 7 common dialog boxes is that you can add any of these controls to them and use those controls to perform special tasks (at least within limits). For example, if users are having a hard time understanding a particular dialog box, you can add a Help button with additional specialized instructions.

Unfortunately, you'll find that there are limits to what you can do with the dialog box itself. Many of the controls are locked down once you display the dialog box. For example, you can't modify the appearance of the dialog box after you display it. In addition, some properties aren't defined at the time you display the dialog box. As a result, you can't write code to clear the file selections the user has made.

All these controls have a complete selection of standard events. When a user clicks a button, you can monitor the event and handle it, if desired. The standard automation for creating event handlers also works, so you don't have to worry about defining the proper syntax. Simply press Tab twice as you normally would to create the event handler entries. The ability to modify the common dialog boxes provides great flexibility, yet you still obtain all the benefits of using a common dialog box in your application, including a standardized appearance.

In addition to the standard controls, you also have access to abstract container controls. Here are the controls you can access:

  • CommonFileDialogControl: Provides an abstract class that contains all the shared functionality for the common file dialog controls.

  • CommonFileDialogControlCollection<T>: Creates a collection of strongly typed dialog box controls.

  • CommonFileDialogProminentControl: Specifies the properties and constructors for all prominent controls in common file dialogs.


2. Configuring the Common File Dialogs Example

The example begins with a Windows Forms application. The example uses one Button control named btnOpen to demonstrate the File Open common dialog and a second Button control named btnSave to demonstrate the File Save common dialog. Of course, you can use any other suitable control, such as a menu, if desired.

Because this application relies on the Code Pack, you need to add references to it. In this case, you need to add references to the following DLLs using the Browse tab of the Add Reference dialog box:

Microsoft.WindowsAPICodePack.DLL
Microsoft.WindowsAPICodePack.Shell.DLL

In addition, this example requires use of the following references from the .NET tab of the Add Reference dialog box:

PresentationCore
PresentationFramework
System.Xaml
WindowsBase

Depending on the application requirements, you also need to add from one to three using statements. In most cases, it's best to add the following using statements to your application:

using Microsoft.WindowsAPICodePack.Dialogs;
using Microsoft.WindowsAPICodePack.Dialogs.Controls;
using Microsoft.WindowsAPICodePack.Shell;

Other  
  •  Programming Excel with VBA and .NET : Variables (part 4) - User-Defined Types & Objects
  •  Programming Excel with VBA and .NET : Variables (part 3) - Constants, Enumerations & Arrays
  •  Programming Excel with VBA and .NET : Variables (part 2) - Conversions, Scope and Lifetime
  •  Programming Excel with VBA and .NET : Variables (part 1) - Names & Declarations
  •  Windows Vista : Performing Local PC Administration (part 2) - Performing common workstation administration tasks
  •  Windows Vista : Performing Local PC Administration (part 1) - Working with workstation administration tools
  •  Filtering Out Evil with Firewalls (part 3) - Manually Configuring a Firewall's Ports
  •  Filtering Out Evil with Firewalls (part 2)
  •  Filtering Out Evil with Firewalls (part 1)
  •  Windows 7 : Windows Driver Foundation Architecture (part 4) - Tools for Development and Testing
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    Video Sports
    programming4us programming4us
    programming4us
     
     
    programming4us