New Controls and Dialogs


Windows Vista delivers several new controls. The command link control is an extension to the Button control and is used with several other controls. The task dialog is a next-generation MessageBox, and for opening and saving files new dialogs are available as well.

Command Link

Command link controls are an extension to the Windows Button control. Command links contain an optional icon and a note text. This control is often used in task dialogs and wizards. Figure 44-4 shows two command link controls that give much more information than Button controls with OK and Cancel content.

image from book
Figure 44-4

With .NET applications, you can create command link controls by using the Vista Bridge sample library. If you add the project VistaBridgeLibrary to your solution, you can add CommandLinkWinForms controls from the toolbox to your Windows Forms application. The class CommandLinkWinForms derives from the System.Windows.Forms.Button class. A command link is an extension to the native Windows Button and defines additional Window messages and a new style to configure the Button. The wrapper class CommandLinkWinForms sends the Window messages BCM_SETNOTE and BCM_SETSHIELD and sets the style BS_COMMANDLINK. The public methods and properties offered in addition to the members of the Button class are NoteText and ShieldIcon.

The following code segment creates a new command link control that sets the NoteText and ShieldIcon. Figure 44-5 shows the configured command link during runtime.

image from book
Figure 44-5

  this.commandLinkDemo =       new Microsoft.SDK.Samples.VistaBridge.Library.CommandLinkWinForms(); this.commandLinkDemo.NoteText =       "The application deletes important files on your system"; this.commandLinkDemo.ShieldIcon = true; this.commandLinkDemo.Size = new System.Drawing.Size(275, 68); this.commandLinkDemo.Text = "Give access to this computer"; this.commandLinkDemo.UseVisualStyleBackColor = true; this.Controls.Add(commandLinkDemo); 

Task Dialog

The task dialog is a next-generation dialog that replaces the old message box. The task dialog is part of the new common controls. The Windows API defines the functions TaskDialog and TaskDialogIndirect to create task dialogs. TaskDialog allows you to create simple dialogs; TaskDialogIndirect is used to create more complex dialogs that contain command link controls and expanded content.

With the Vista Bridge library, the native API call to TaskDialogIndirect() is wrapped with PInvoke:

  [DllImport(ExternDll.ComCtl32, CharSet = CharSet.Auto, SetLastError = true)] internal static extern HRESULT TaskDialogIndirect(    [In] NativeMethods.TASKDIALOGCONFIG pTaskConfig,    [Out] out int pnButton,    [Out] out int pnRadioButton,    [Out] out bool pVerificationFlagChecked); 

The first parameter of TaskDialogIndirect() is defined as a TASKDIALOGCONFIG class that maps to the same structure of the native API call:

  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] internal class TASKDIALOGCONFIG {    internal uint cbSize;    internal IntPtr hwndParent;    internal IntPtr hInstance;    internal TASKDIALOG_FLAGS dwFlags;    internal TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszWindowTitle;    internal TASKDIALOGCONFIG_ICON_UNION MainIcon;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszMainInstruction;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszContent;    internal uint cButtons;    internal IntPtr pButtons;           // Ptr to TASKDIALOG_BUTTON structs    internal int nDefaultButton;    internal uint cRadioButtons;    internal IntPtr pRadioButtons;      // Ptr to TASKDIALOG_BUTTON structs    internal int nDefaultRadioButton;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszVerificationText;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszExpandedInformation;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszExpandedControlText;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszCollapsedControlText;    internal TASKDIALOGCONFIG_ICON_UNION FooterIcon;    [MarshalAs(UnmanagedType.LPWStr)]    internal string pszFooter;    internal PFTASKDIALOGCALLBACK pfCallback;    internal IntPtr lpCallbackData;    internal uint cxWidth; } 

The public class from Vista Bridge used to show task dialogs is TaskDialog. To display a simple dialog, only the static method Show() must be invoked. The simple dialog is shown in Figure 44-6.

image from book
Figure 44-6

  TaskDialog.Show("Simple Task Dialog"); 

For more features of the TaskDialog class, the properties Caption, Content, StandardButtons, and MainIcon are set. You can see the result with Figure 44-7.

image from book
Figure 44-7

  TaskDialog dlg1 = new TaskDialog(); dlg1.Caption = "Title"; dlg1.Content = "Some Information"; dlg1.StandardButtons = TaskDialogStandardButtons.OkCancel; dlg1.MainIcon = TaskDialogStandardIcon.Information; dlg1.Show(); 

With the task dialog you can set the shield icon that was first shown with command links. Also, you can expand it by setting the ExpansionMode property. With the enumeration TaskDialogExpandedInformationLocation, you can specify that either the content or the footer should be expanded. Figure 44-8 shows the task dialog in collapsed mode; Figure 44-9 shows it in expanded mode.

image from book
Figure 44-8

image from book
Figure 44-9

  TaskDialog dlg2 = new TaskDialog(); dlg2.Caption = "Title"; dlg2.Content = "Some Information"; dlg2.StandardButtons = TaskDialogStandardButtons.YesNo; dlg2.MainIcon = TaskDialogStandardIcon.Shield; dlg2.ExpandedText = "Additional Text"; dlg2.ExpandedControlText = "More information"; dlg2.CollapsedControlText = "Less information"; dlg2.ExpansionMode = TaskDialogExpandedInformationLocation.ExpandContent; dlg2.FooterText = "Footer Information"; dlg2.FooterIcon = TaskDialogStandardIcon.Information; dlg2.Show(); 

A task dialog can also contain other controls. In the following code snippet, a task dialog is created that contains two radio buttons, a command link, and a marquee control. You’ve already seen command links in the previous section, and indeed command links are used very frequently within task dialogs. Figure 44-10 shows the task dialog with the controls in the content area. Of course, you can also combine expansion mode with controls.

image from book
Figure 44-10

  TaskDialogRadioButton radio1 = new TaskDialogRadioButton(); radio1.Name = "radio1"; radio1.Text = "One"; TaskDialogRadioButton radio2 = new TaskDialogRadioButton(); radio2.Name = "radio2"; radio2.Text = "Two"; TaskDialogCommandLink commandLink = new TaskDialogCommandLink(); commandLink.Name = "link1"; commandLink.ShowElevationIcon = true; commandLink.Text = "Information"; commandLink.Instruction = "Sample Command Link"; TaskDialogMarquee marquee = new TaskDialogMarquee(); marquee.Name = "marquee"; marquee.State = TaskDialogProgressBarState.Normal; TaskDialog dlg3 = new TaskDialog(); dlg3.Caption = "Title"; dlg3.Instruction = "Sample Task Dialog"; dlg3.Controls.Add(radio1); dlg3.Controls.Add(radio2); dlg3.Controls.Add(commandLink); dlg3.Controls.Add(marquee); dlg3.Show(); 

File Dialogs

Dialogs to open and save files have changed. Figure 44-11 shows the traditional file open dialog that is wrapped both from the Windows Forms class System.Windows.Forms.OpenFileDialog and the wrapper class for WPF in the assembly PresentationFramework: Microsoft.Win32.OpenFileDialog.

image from book
Figure 44-11

The new Windows Vista dialog is shown in Figure 44-12. This dialog has Navigation, Details, and Preview panes that can be configured from the Organize image from book Layout menu. This dialog also contains search functionality and is completely customizable. In the Vista Bridge library, this dialog is wrapped from the CommonOpenFileDialog class.

image from book
Figure 44-12

  CommonOpenFileDialog dlg = new CommonOpenFileDialog(); dlg.ShowDialog(); 

The new Windows Vista dialog for saving files is customizable as well. By default, it defines a collapsed (see Figure 44-13) and an expanded mode (see Figure 44-14). This dialog is wrapped in the class CommonSaveDialog.

image from book
Figure 44-13

image from book
Figure 44-14




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net