Click here to Skip to main content
15,891,529 members
Articles / Desktop Programming / Windows Forms

Windows Ribbon for WinForms, Part 3 - First WinForms Ribbon Application

Rate me:
Please Sign up or sign in to vote.
4.29/5 (18 votes)
4 Mar 2010Ms-PL4 min read 53.1K   3.8K   32  
In this article, I'll present how to create an empty WinForms application with Windows 7 ribbon support.
//*****************************************************************************
//
//  File:       RibbonDropDownColorPicker.cs
//
//  Contents:   Helper class that wraps a ribbon drop down color picker control.
//
//*****************************************************************************

using System.Drawing;
using RibbonLib.Controls.Events;
using RibbonLib.Controls.Properties;
using RibbonLib.Interop;

namespace RibbonLib.Controls
{
    public class RibbonDropDownColorPicker : BaseRibbonControl,
        IColorPickerPropertiesProvider,
        IEnabledPropertiesProvider,
        IKeytipPropertiesProvider,
        ILabelPropertiesProvider,
        IImagePropertiesProvider,
        ITooltipPropertiesProvider,
        IExecuteEventsProvider,
        IPreviewEventsProvider
    {
        private ColorPickerPropertiesProvider _colorPickerPropertiesProvider;
        private EnabledPropertiesProvider _enabledPropertiesProvider;
        private KeytipPropertiesProvider _keytipPropertiesProvider;
        private LabelPropertiesProvider _labelPropertiesProvider;
        private ImagePropertiesProvider _imagePropertiesProvider;
        private TooltipPropertiesProvider _tooltipPropertiesProvider;
        private ExecuteEventsProvider _executeEventsProvider;
        private PreviewEventsProvider _previewEventsProvider;

        public RibbonDropDownColorPicker(Ribbon ribbon, uint commandId)
            : base(ribbon, commandId)
        {
            AddPropertiesProvider(_colorPickerPropertiesProvider = new ColorPickerPropertiesProvider(ribbon, commandId));
            AddPropertiesProvider(_enabledPropertiesProvider = new EnabledPropertiesProvider(ribbon, commandId));
            AddPropertiesProvider(_keytipPropertiesProvider = new KeytipPropertiesProvider(ribbon, commandId));
            AddPropertiesProvider(_labelPropertiesProvider = new LabelPropertiesProvider(ribbon, commandId));
            AddPropertiesProvider(_imagePropertiesProvider = new ImagePropertiesProvider(ribbon, commandId));
            AddPropertiesProvider(_tooltipPropertiesProvider = new TooltipPropertiesProvider(ribbon, commandId));
        
            AddEventsProvider(_executeEventsProvider = new ExecuteEventsProvider());
            AddEventsProvider(_previewEventsProvider = new PreviewEventsProvider());
        }

        #region IColorPickerPropertiesProvider Members

        public string AutomaticColorLabel
        {
            get
            {
                return _colorPickerPropertiesProvider.AutomaticColorLabel;
            }
            set
            {
                _colorPickerPropertiesProvider.AutomaticColorLabel = value;
            }
        }

        public Color Color
        {
            get
            {
                return _colorPickerPropertiesProvider.Color;
            }
            set
            {
                _colorPickerPropertiesProvider.Color = value;
            }
        }

        public SwatchColorType ColorType
        {
            get
            {
                return _colorPickerPropertiesProvider.ColorType;
            }
            set
            {
                _colorPickerPropertiesProvider.ColorType = value;
            }
        }

        public string MoreColorsLabel
        {
            get
            {
                return _colorPickerPropertiesProvider.MoreColorsLabel;
            }
            set
            {
                _colorPickerPropertiesProvider.MoreColorsLabel = value;
            }
        }

        public string NoColorLabel
        {
            get
            {
                return _colorPickerPropertiesProvider.NoColorLabel;
            }
            set
            {
                _colorPickerPropertiesProvider.NoColorLabel = value;
            }
        }

        public string RecentColorsCategoryLabel
        {
            get
            {
                return _colorPickerPropertiesProvider.RecentColorsCategoryLabel;
            }
            set
            {
                _colorPickerPropertiesProvider.RecentColorsCategoryLabel = value;
            }
        }

        public Color[] StandardColors
        {
            get
            {
                return _colorPickerPropertiesProvider.StandardColors;
            }
            set
            {
                _colorPickerPropertiesProvider.StandardColors = value;
            }
        }

        public string StandardColorsCategoryLabel
        {
            get
            {
                return _colorPickerPropertiesProvider.StandardColorsCategoryLabel;
            }
            set
            {
                _colorPickerPropertiesProvider.StandardColorsCategoryLabel = value;
            }
        }

        public string[] StandardColorsTooltips
        {
            get
            {
                return _colorPickerPropertiesProvider.StandardColorsTooltips;
            }
            set
            {
                _colorPickerPropertiesProvider.StandardColorsTooltips = value;
            }
        }

        public Color[] ThemeColors
        {
            get
            {
                return _colorPickerPropertiesProvider.ThemeColors;
            }
            set
            {
                _colorPickerPropertiesProvider.ThemeColors = value;
            }
        }

        public string ThemeColorsCategoryLabel
        {
            get
            {
                return _colorPickerPropertiesProvider.ThemeColorsCategoryLabel;
            }
            set
            {
                _colorPickerPropertiesProvider.ThemeColorsCategoryLabel = value;
            }
        }

        public string[] ThemeColorsTooltips
        {
            get
            {
                return _colorPickerPropertiesProvider.ThemeColorsTooltips;
            }
            set
            {
                _colorPickerPropertiesProvider.ThemeColorsTooltips = value;
            }
        }

        #endregion

        #region IEnabledPropertiesProvider Members

        public bool Enabled
        {
            get
            {
                return _enabledPropertiesProvider.Enabled;
            }
            set
            {
                _enabledPropertiesProvider.Enabled = value;
            }
        }

        #endregion

        #region IKeytipPropertiesProvider Members

        public string Keytip
        {
            get
            {
                return _keytipPropertiesProvider.Keytip;
            }
            set
            {
                _keytipPropertiesProvider.Keytip = value;
            }
        }

        #endregion

        #region ILabelPropertiesProvider Members

        public string Label
        {
            get
            {
                return _labelPropertiesProvider.Label;
            }
            set
            {
                _labelPropertiesProvider.Label = value;
            }
        }

        #endregion

        #region IImagePropertiesProvider Members

        public IUIImage LargeImage
        {
            get
            {
                return _imagePropertiesProvider.LargeImage;
            }
            set
            {
                _imagePropertiesProvider.LargeImage = value;
            }
        }

        public IUIImage SmallImage
        {
            get
            {
                return _imagePropertiesProvider.SmallImage;
            }
            set
            {
                _imagePropertiesProvider.SmallImage = value;
            }
        }

        public IUIImage LargeHighContrastImage
        {
            get
            {
                return _imagePropertiesProvider.LargeHighContrastImage;
            }
            set
            {
                _imagePropertiesProvider.LargeHighContrastImage = value;
            }
        }

        public IUIImage SmallHighContrastImage
        {
            get
            {
                return _imagePropertiesProvider.SmallHighContrastImage;
            }
            set
            {
                _imagePropertiesProvider.SmallHighContrastImage = value;
            }
        }

        #endregion

        #region ITooltipPropertiesProvider Members

        public string TooltipTitle
        {
            get
            {
                return _tooltipPropertiesProvider.TooltipTitle;
            }
            set
            {
                _tooltipPropertiesProvider.TooltipTitle = value;
            }
        }

        public string TooltipDescription
        {
            get
            {
                return _tooltipPropertiesProvider.TooltipDescription;
            }
            set
            {
                _tooltipPropertiesProvider.TooltipDescription = value;
            }
        }

        #endregion

        #region IExecuteEventsProvider Members

        public event OnExecuteEventHandler OnExecute
        {
            add
            {
                _executeEventsProvider.OnExecute += value;
            }
            remove
            {
                _executeEventsProvider.OnExecute -= value;
            }
        }

        #endregion

        #region IPreviewEventsProvider Members

        public event OnPreviewEventHandler OnPreview
        {
            add
            {
                _previewEventsProvider.OnPreview += value;
            }
            remove
            {
                _previewEventsProvider.OnPreview -= value;
            }
        }

        public event OnCancelPreviewEventHandler OnCancelPreview
        {
            add
            {
                _previewEventsProvider.OnCancelPreview += value;
            }
            remove
            {
                _previewEventsProvider.OnCancelPreview -= value;
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).

Comments and Discussions