using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace TaskbarLib.DesktopIntegration.WindowsForms
{
///
/// Contains extension methods for easier Windows Forms interop.
///
public static class WindowsFormsExtensions
{
///
/// Sets this form's application id.
///
/// The form.
/// The application id.
public static void SetAppId(this Form form, string appId)
{
Windows7Taskbar.SetWindowAppId(form.Handle, appId);
}
///
/// Gets this form's application id.
///
/// The form.
/// The form's application id.
public static string GetAppId(this Form form)
{
return Windows7Taskbar.GetWindowAppId(form.Handle);
}
///
/// Enables custom window preview on this form, meaning that
/// the DWM will send messages when a live thumbnail preview
/// or a live peek will be necessary.
///
/// The form.
public static void EnableCustomWindowPreview(this Form form)
{
Windows7Taskbar.EnableCustomWindowPreview(form.Handle);
}
///
/// Disables custom window preview on this form, meaning that
/// the DWM will not send messages when a live thumbnail preview
/// or a live peek will be necessary, but instead rely on its
/// default rendering.
///
/// The form.
public static void DisableCustomWindowPreview(this Form form)
{
Windows7Taskbar.DisableCustomWindowPreview(form.Handle);
}
///
/// Sets this form's iconic thumbnail to the specified bitmap.
///
/// The form.
/// The bitmap.
public static void SetIconicThumbnail(this Form form, Bitmap bitmap)
{
Windows7Taskbar.SetIconicThumbnail(form.Handle, bitmap);
}
///
/// Sets this form's peek (live preview) bitmap.
///
/// The form.
/// The bitmap.
/// Whether to display a standard window
/// frame around the bitmap.
public static void SetPeekBitmap(this Form form, Bitmap bitmap, bool displayFrame)
{
Windows7Taskbar.SetPeekBitmap(form.Handle, bitmap, displayFrame);
}
///
/// Draws the specified overlay icon over this form's taskbar button.
///
/// The form.
/// The overlay icon.
/// The overlay icon's description.
public static void SetTaskbarOverlayIcon(this Form form, Icon icon, string description)
{
Windows7Taskbar.SetTaskbarOverlayIcon(form.Handle, icon, description);
}
///
/// Sets the progress bar in the containing form's taskbar button
/// to this progress bar's progress.
///
/// The progress bar.
public static void SetTaskbarProgress(ProgressBar progressBar)
{
Form form = (Form)progressBar.TopLevelControl;
//Approximation:
ulong maximum = (ulong)(progressBar.Maximum - progressBar.Minimum);
ulong progress = (ulong)(progressBar.Value - progressBar.Minimum);
Windows7Taskbar.SetProgressState(form.Handle, Windows7Taskbar.ThumbnailProgressState.Normal);
Windows7Taskbar.SetProgressValue(form.Handle, progress, maximum);
}
///
/// Sets the progress bar in the containing form's taskbar button
/// to this toolstrip progress bar's progress.
///
/// The progress bar.
public static void SetTaskbarProgress(ToolStripProgressBar progressBar)
{
Form form = (Form)progressBar.Control.TopLevelControl;
//Approximation:
ulong maximum = (ulong)(progressBar.Maximum - progressBar.Minimum);
ulong progress = (ulong)(progressBar.Value - progressBar.Minimum);
Windows7Taskbar.SetProgressState(form.Handle, Windows7Taskbar.ThumbnailProgressState.Normal);
Windows7Taskbar.SetProgressValue(form.Handle, progress, maximum);
}
///
/// Sets the progress bar of this form's taskbar button to the
/// specified percentage.
///
/// The form.
/// The progress percentage.
public static void SetTaskbarProgress(this Form form, float percent)
{
Windows7Taskbar.SetProgressState(form.Handle, Windows7Taskbar.ThumbnailProgressState.Normal);
Windows7Taskbar.SetProgressValue(form.Handle, (ulong)percent, 100);
}
///
/// Sets the progress bar of this form's taskbar button to the
/// specified state.
///
/// The form.
/// The taskbar progress state.
public static void SetTaskbarProgressState(this Form form, Windows7Taskbar.ThumbnailProgressState state)
{
Windows7Taskbar.SetProgressState(form.Handle, state);
}
///
/// Creates a taskbar thumbnail button manager for this form.
///
/// The form.
/// An object of type
/// that can be used to add and manage thumbnail toolbar buttons.
public static ThumbButtonManager CreateThumbButtonManager(this Form form)
{
return new ThumbButtonManager(form.Handle);
}
///
/// Creates a jump list manager for this form.
///
/// The form.
/// An object of type
/// that can be used to manage the application's jump list.
public static JumpListManager CreateJumpListManager(this Form form)
{
return new JumpListManager(form.Handle);
}
///
/// Specifies that only a portion of the form's client area
/// should be used in the form's thumbnail.
///
/// The form.
/// The rectangle that specifies the clipped region.
public static void SetThumbnailClip(this Form form, Rectangle clipRect)
{
Windows7Taskbar.SetThumbnailClip(form.Handle, clipRect);
}
///
/// Sets the specified form's thumbnail tooltip.
///
/// The form.
/// The tooltip text.
public static void SetThumbnailTooltip(this Form form, string tooltip)
{
Windows7Taskbar.SetThumbnailTooltip(form.Handle, tooltip);
}
}
}