using System; using System.Text; using System.ComponentModel; using System.Drawing; namespace DevComponents.DotNetBar { /// /// Represents the color picker button control. /// [ToolboxBitmap(typeof(ColorPickerButton), "Controls.ColorPickerButton.ico"), ToolboxItem(true), DefaultEvent("SelectedColorChanged"), Designer("DevComponents.DotNetBar.Design.ColorPickerButtonDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf"), System.Runtime.InteropServices.ComVisible(false)] public class ColorPickerButton : ButtonX { #region Private Variables #endregion #region Events /// /// Occurs when color is chosen from drop-down color picker or from Custom Colors dialog box. Selected color can be accessed through SelectedColor property. /// [Description("Occurs when color is chosen from drop-down color picker or from Custom Colors dialog box.")] public event EventHandler SelectedColorChanged; /// /// Occurs when mouse is moving over the colors presented by the color picker. You can use it to preview the color before it is selected. /// [Description("Occurs when mouse is moving over the colors presented by the color picker")] public event ColorPreviewEventHandler ColorPreview; #endregion #region Constructor /// /// Creates new instance of the object. /// public ColorPickerButton() : base() { ColorPickerDropDown cp = GetColorPickerDropDown(); cp.SelectedColorChanged += new EventHandler(InternalSelectedColorChanged); cp.ColorPreview += new ColorPreviewEventHandler(InternalColorPreview); } #endregion #region Internal Implementation #if FRAMEWORK20 /// /// Gets or sets the array of ColorItem objects that will be used as standard colors instead of built-in color palette. /// See: http://www.devcomponents.com/kb2/?p=79 for instructions. /// [DefaultValue(null), Browsable(false), Category("Colors"), Description("Array of ColorItem objects that will be used as standard colors instead of built-in color palette.")] public ColorItem[][] CustomStandardColors { get { return GetColorPickerDropDown().CustomStandardColors; } set { GetColorPickerDropDown().CustomStandardColors = value; } } /// /// Gets or sets the array of ColorItem objects that will be used as theme colors instead of built-in color palette. /// See: http://www.devcomponents.com/kb2/?p=79 for instructions. /// [DefaultValue(null), Browsable(false), Category("Colors"), Description("Array of ColorItem objects that will be used as theme colors instead of built-in color palette.")] public ColorItem[][] CustomThemeColors { get { return GetColorPickerDropDown().CustomThemeColors; } set { GetColorPickerDropDown().CustomThemeColors = value; } } #endif /// /// Displays the Colors dialog that allows user to choose the color or create a custom color. If new color is chosen the /// SelectedColorChanged event is raised. /// public System.Windows.Forms.DialogResult DisplayMoreColorsDialog() { return GetColorPickerDropDown().DisplayMoreColorsDialog(); } protected override ButtonItem CreateButtonItem() { return new ColorPickerDropDown(); } private ColorPickerDropDown GetColorPickerDropDown() { return InternalItem as ColorPickerDropDown; } private void InternalColorPreview(object sender, ColorPreviewEventArgs e) { OnColorPreview(e); } /// /// Raises the ColorPreview event. /// /// Provides event data. protected virtual void OnColorPreview(ColorPreviewEventArgs e) { if (ColorPreview != null) ColorPreview(this, e); } private void InternalSelectedColorChanged(object sender, EventArgs e) { OnSelectedColorChanged(e); ExecuteCommand(); } /// /// Gets whether command is executed when button is clicked. /// protected virtual bool ExecuteCommandOnClick { get { return false; } } /// /// Raises the SelectedColorChanged event. /// /// Provides event data. protected virtual void OnSelectedColorChanged(EventArgs e) { if (SelectedColorChanged != null) SelectedColorChanged(this, e); } /// /// Gets or sets the Owner Window that will be used as owner for the colors modal dialog when displayed. /// [Browsable(false), DefaultValue(null)] public System.Windows.Forms.IWin32Window OwnerWindow { get { return GetColorPickerDropDown().OwnerWindow; } set { GetColorPickerDropDown().OwnerWindow = value; } } /// /// Gets or sets more colors menu item is visible which allows user to open Custom Colors dialog box. Default value is true. /// [Browsable(true), DefaultValue(true), DevCoSerialize(), Category("Appearance"), Description("Indicates more colors menu item is visible which allows user to open Custom Colors dialog box.")] public bool DisplayMoreColors { get { return GetColorPickerDropDown().DisplayMoreColors; } set { GetColorPickerDropDown().DisplayMoreColors = value; } } /// /// Gets or sets the last selected color from either the drop-down or Custom Color dialog box. Default value is /// Color.Empty. You can use SelectedColorChanged event to be notified when this property changes. /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public Color SelectedColor { get { return GetColorPickerDropDown().SelectedColor; } set { GetColorPickerDropDown().SelectedColor = value; } } /// /// Gets or sets whether theme colors are displayed on drop-down. Default value is true. /// [Browsable(true), DefaultValue(true), DevCoSerialize(), Category("Appearance"), Description("Indicates whether theme colors are displayed on drop-down.")] public bool DisplayThemeColors { get { return GetColorPickerDropDown().DisplayThemeColors; } set { GetColorPickerDropDown().DisplayThemeColors = value; } } /// /// Gets or sets whether standard colors are displayed on drop-down. Default value is true. /// [Browsable(true), DefaultValue(true), DevCoSerialize(), Category("Appearance"), Description("Indicates whether standard colors are displayed on drop-down.")] public bool DisplayStandardColors { get { return GetColorPickerDropDown().DisplayStandardColors; } set { GetColorPickerDropDown().DisplayStandardColors = value; } } /// /// Indicates whether SubItems collection is serialized. ColorPickerDropDown does not serialize the sub items. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeSubItems() { return false; } /// /// Gets or sets the rectangle in Image coordinates where selected color will be painted. Setting this property will /// have an effect only if Image property is used to set the image. Default value is an empty rectangle which indicates /// that selected color will not be painted on the image. /// [Browsable(true), Description("Indicates rectangle in Image coordinates where selected color will be painted. Property will have effect only if Image property is used to set the image."), Category("Behaviour")] public Rectangle SelectedColorImageRectangle { get { return GetColorPickerDropDown().SelectedColorImageRectangle; } set { GetColorPickerDropDown().SelectedColorImageRectangle = value; } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeSelectedColorImageRectangle() { return GetColorPickerDropDown().ShouldSerializeSelectedColorImageRectangle(); } /// /// Resets the property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] public void ResetSelectedColorImageRectangle() { GetColorPickerDropDown().ResetSelectedColorImageRectangle(); } /// /// Invokes the ColorPreview event. /// /// Provides data for the event. public void InvokeColorPreview(ColorPreviewEventArgs e) { GetColorPickerDropDown().InvokeColorPreview(e); } /// /// Update the selected color image if the SelectedColorImageRectangle has been set and button is using Image property to display the image. /// public void UpdateSelectedColorImage() { GetColorPickerDropDown().UpdateSelectedColorImage(); } #endregion } }