packages/Windows API Code Pack 1.1/source/Samples/Shell/ShellThumbnailBrowserDemo/CS/ThumbnailBrowserDemo/ThumbnailBrowser.cs
/// <summary>
/// Updates the thumbnail preview for currently selected item and current view
/// </summary>
Updates the thumbnail preview for currently selected item and current view
Updates the thumbnail preview for currently selected item and current view
private void UpdatePreview()
        {
            if (currentItem != null)
            {
                if (currentMode == Mode.ThumbnailOrIcon)
                    currentItem.Thumbnail.FormatOption = ShellThumbnailFormatOption.Default;
                else if (currentMode == Mode.ThumbnailOnly)
                    currentItem.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;
                else
                    currentItem.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
                try
                {
                    if (currentView == Views.Small)
                        pictureBox1.Image = currentItem.Thumbnail.SmallBitmap;
                    else if (currentView == Views.Medium)
                        pictureBox1.Image = currentItem.Thumbnail.MediumBitmap;
                    else if (currentView == Views.Large)
                        pictureBox1.Image = currentItem.Thumbnail.LargeBitmap;
                    else if (currentView == Views.ExtraLarge)
                        pictureBox1.Image = currentItem.Thumbnail.ExtraLargeBitmap;
                }
                catch (NotSupportedException)
                {
                    TaskDialog tdThumbnailHandlerError = new TaskDialog();
                    tdThumbnailHandlerError.Caption = "Error getting the thumbnail";
                    tdThumbnailHandlerError.InstructionText = "The selected file does not have a valid thumbnail or thumbnail handler.";
                    tdThumbnailHandlerError.Icon = TaskDialogStandardIcon.Error;
                    tdThumbnailHandlerError.StandardButtons = TaskDialogStandardButtons.Ok;
                    tdThumbnailHandlerError.Show();
                }
                catch (InvalidOperationException)
                {
                    if (currentMode == Mode.ThumbnailOnly)
                    {
                        if (showErrorTaskDialog)
                        {
                            TaskDialogResult tdr = td.Show();
                            showErrorTaskDialog = !td.FooterCheckBoxChecked.Value;
                        }
                        if (onErrorChangeMode)
                        {
                            comboBox1.SelectedIndex = 0;
                            UpdatePreview();
                        }
                        else 
                            pictureBox1.Image = null;
                    }
                    else
                        pictureBox1.Image = null;
                }
            }
            else
                pictureBox1.Image = null;
        }
private void UpdatePreview ( ) { if ( currentItem != null ) { if ( currentMode == Mode . ThumbnailOrIcon ) currentItem . Thumbnail . FormatOption = ShellThumbnailFormatOption . Default ; else if ( currentMode == Mode . ThumbnailOnly ) currentItem . Thumbnail . FormatOption = ShellThumbnailFormatOption . ThumbnailOnly ; else currentItem . Thumbnail . FormatOption = ShellThumbnailFormatOption . IconOnly ; try { if ( currentView == Views . Small ) pictureBox1 . Image = currentItem . Thumbnail . SmallBitmap ; else if ( currentView == Views . Medium ) pictureBox1 . Image = currentItem . Thumbnail . MediumBitmap ; else if ( currentView == Views . Large ) pictureBox1 . Image = currentItem . Thumbnail . LargeBitmap ; else if ( currentView == Views . ExtraLarge ) pictureBox1 . Image = currentItem . Thumbnail . ExtraLargeBitmap ; } catch ( NotSupportedException ) { TaskDialog tdThumbnailHandlerError = new TaskDialog ( ) ; tdThumbnailHandlerError . Caption = " " ; tdThumbnailHandlerError . InstructionText = " " ; tdThumbnailHandlerError . Icon = TaskDialogStandardIcon . Error ; tdThumbnailHandlerError . StandardButtons = TaskDialogStandardButtons . Ok ; tdThumbnailHandlerError . Show ( ) ; } catch ( InvalidOperationException ) { if ( currentMode == Mode . ThumbnailOnly ) { if ( showErrorTaskDialog ) { TaskDialogResult tdr = td . Show ( ) ; showErrorTaskDialog = ! td . FooterCheckBoxChecked . Value ; } if ( onErrorChangeMode ) { comboBox1 . SelectedIndex = 0 ; UpdatePreview ( ) ; } else pictureBox1 . Image = null ; } else pictureBox1 . Image = null ; } } else pictureBox1 . Image = null ; }
Updates the thumbnail preview for currently selected item and current view
Updates the thumbnail preview for currently selected item and current view
// Set the appropiate FormatOption // Get the correct bitmap // If we get an InvalidOperationException and our mode is Mode.ThumbnailOnly, // then we have a ShellItem that doesn't have a thumbnail (icon only). // Let the user know this and if they want, change the mode. // If the user picked the first option, change the mode... // Change the mode to ThumbnailOrIcon // else, ignore and display nothing.