
Clicking anywhere on the button displays a drop-down palette. In the DropDown mode, the control appears with a colored box and a small down arrow. In this mode, the control does not display any palette. For example, if there are only three color options, you might place three ColorPicker controls on a form with their Mode properties set to ButtonOnly. Use this mode when you want the user to be able to select a pre-defined color by clicking this button. In the ButtonOnly mode, the control is just a clickable button. You can set the Mode property to one of three values: ButtonOnly, DropDown and Split. The ColorPicker control is a button that displays a colored box instead of text. The SelectionChanged event occurs as different palette items are selected, either using the arrow keys or by hovering the mouse over the palette. The Click event occurs when the user selects a color and presses Enter, or clicks a color with the mouse. This control provides two events: Click and SelectionChanged. If VisibleRows is less than the number of rows in the palette, the control displays a scroll bar so that the entire palette can be accessed. This property sets the maximum number of rows displayed. You can also set the VisibleRows property to a non-zero value. This control has a few extras such as properties to set the width of each color box ( BoxWidth), the height of each color box ( BoxHeight), the spacing between each color box ( Margins), and the number of boxes per row ( Columns).
Wpf colorpicker code#
Listing 1: Populating the Palette from Code private void TestColorPalette_Load( object sender, System.EventArgs e)Ĭ(Color.FromArgb(i, i, i)) Important: When modifying the ColorItems collection from your code, be sure to call the UpdateLayout() method when you are finished in order for the control to correctly display the updated palette. You control which colors are available in the palette either by assigning one of the pre-defined palettes to the DefaultPalette property, or by populating the palette programmatically at run time. The available colors are stored in the ColorItems property. It allows the user to select from a palette of colors, which are displayed in a grid. The ColorPalette control is really the core of all the ColorPicker controls. Not only is this a great control for implementing any sort of drop-down or pop-up window, but it also works with ToolStripDropDownButton buttons, which means it can work in a ToolStrip container. This control implements the logic for the drop-down window and is used by those controls that implement a drop-down palette.ĬolorDropDown inherits from the ToolStripDropDown control. There is a fifth control, ColorDropDown, which is private. Two of the controls can be placed directly on a form, while the other two can be placed in a ToolStrip container. I compiled them all into a single file (ColorPicker.dll). The result was no less than four custom controls.


In addition, I could immediately see that it would be useful if I could place a color picker control directly into a WinForms ToolStrip container. For example, sometimes I just wanted a button, and other times I wanted a drop-down palette. Right away, the first issue I had was that I realized I needed different types of controls. I started playing around with different ways to implement a more sophisticated color picker. I also stated that, perhaps, I might someday create a fancier color picker that does not fit within the rigid structure of an owner-draw combo box. In that article, I stated that an owner-draw combo box seemed like the easiest way to implement a color picker for WinForms. Previously, I wrote about using an owner-draw combo box to implement a color picker control.
Wpf colorpicker download#
Download Source Code for Controls Introduction
