Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
395
Colour picker control
posted

Hi,
I'm just encapsulating the ultra colour picker for our app framework.  I want to be able to not show the text value of the colour.  So it just shows the colour block.  Is there a way to do this?  Or do I just need to limit the size of the control so you can't see the colour bit? (thats a bit of a nasty way to do it!)

Also more importantly how do the colour names and tabs react when in difference languages? 

Really we only need the colour picker/custom colour tab, not the Web/System tabs, can we disable them?

Regards
Chris

Parents
  • 4940
    Offline posted

    This is slight overkill and it's better to use Mike's advice, but here's how you can do it. On your project in Visual Studio, add a new Custom Control named UltraColorPickerPlus. Afterwards, paste the code below inside the namespace so it replaces the generated skeleton.

     

        public partial class UltraColorPickerPlus : Infragistics.Win.UltraWinEditors.UltraComboEditor, Infragistics.Win.IUIElementCreationFilter
        {
            private Infragistics.Win.UltraWinEditors.UltraPictureBoxControlUIElement ColorElement;
            private Infragistics.Win.UltraWinEditors.UltraPictureBox picturebox = new Infragistics.Win.UltraWinEditors.UltraPictureBox();
            private Infragistics.Win.Misc.UltraPopupControlContainer PopupControl = new Infragistics.Win.Misc.UltraPopupControlContainer();
            private MyTabbedColorPicker ColorPicker = new MyTabbedColorPicker();
    
            public delegate void ColorPickedHandler(object sender, ColorPickerArgs ca);
            public event ColorPickedHandler ColorPicked;
    
            public override string Text
            {
                get
                {
                    base.Text = string.Empty;
                    return string.Empty;
                }
            }
    
            protected override System.Drawing.Size DefaultSize
            {
                get
                {
                    return new Size(50,30);
                }
            }
    
            public override Infragistics.Win.DropDownStyle DropDownStyle
            {
                get { return Infragistics.Win.DropDownStyle.DropDownList; }
            }
    
            public Color Color
            {
                get { return ColorPicker.Color; }
            }
    
            private bool _UseCustom = true;
            public bool UseCustom
            {
                get { return _UseCustom; }
                set { _UseCustom = value; }
            }
    
            private bool _UseWeb = true;
            public bool UseWeb
            {
                get { return _UseWeb; }
                set { _UseWeb = value; }
            }
    
            private bool _UseSystem = true;
            public bool UseSystem
            {
                get { return _UseSystem; }
                set { _UseSystem = value; }
            }
    
            public UltraColorPickerPlus()
            {
                InitializeComponent();
    
                this.CreationFilter = this;
                this.DropDownStyle = Infragistics.Win.DropDownStyle.DropDownList;
            }
    
            private void coloreditor_ColorChanged(object sender, EventArgs e)
            {
                PopupControl.Close();
                this.picturebox.BackColor = ColorPicker.Color;
                ColorPickerArgs cpa = new ColorPickerArgs(ColorPicker.Color);
                ColorPicked(this, cpa);
            }
    
            protected override void OnBeforeDropDown(CancelEventArgs args)
            {
                ColorPicker = new MyTabbedColorPicker(_UseCustom, _UseWeb, _UseSystem);
                ColorPicker.ColorChanged += new EventHandler(coloreditor_ColorChanged);
                PopupControl.PopupControl = ColorPicker;
                PopupControl.Show();
                args.Cancel = true;
                base.OnBeforeDropDown(args);
            }
    
            public void AfterCreateChildElements(Infragistics.Win.UIElement parent)
            {
                if (parent is Infragistics.Win.UltraWinEditors.UltraComboEditorUIElement)
                {
                    ColorElement = new Infragistics.Win.UltraWinEditors.UltraPictureBoxControlUIElement(picturebox);
                    picturebox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
    
                    Rectangle ColorRect = parent.RectInsideBorders;
                    ColorRect.Height = 16;
                    ColorRect.Width = 16;
                    ColorRect.X = 3;
                    ColorRect.Y = 3;
                    ColorElement.Rect = ColorRect;
    
                    parent.ChildElements.Add(ColorElement);
                }
            }
    
            public bool BeforeCreateChildElements(Infragistics.Win.UIElement parent)
            {
                return false;
            }
        }
    
        public partial class MyTabbedColorPicker : Infragistics.Win.TabbedColorPicker
        {
            private bool UseCustom = true, UseWeb = true, UseSystem = true;
    
            public MyTabbedColorPicker() { }
    
            public MyTabbedColorPicker(bool usecustom, bool useweb, bool usesystem)
            {
                UseCustom = usecustom;
                UseWeb = useweb;
                UseSystem = usesystem;
            }
    
            protected override void OnLoad(EventArgs e)
            {
                for (int passes = 0; passes < 3; passes++)
                {
                    TabControl tabControl = (TabControl)this.Controls[0];
    
                    foreach (Control tab in tabControl.Controls)
                    {
                        if (tab is TabPage)
                        {
                            switch (((TabPage)tab).Text)
                            {
                                case "Custom":
                                    if (!UseCustom)
                                        tabControl.TabPages.Remove((TabPage)tab);
                                    break;
                                case "Web":
                                    if (!UseWeb)
                                        tabControl.TabPages.Remove((TabPage)tab);
                                    break;
                                case "System":
                                    if (!UseSystem)
                                        tabControl.TabPages.Remove((TabPage)tab);
                                    break;
                            }
                        }
                    }
                }
    
                base.OnLoad(e);
            }
        }
    
        public class ColorPickerArgs : System.EventArgs
        {
    
            private Color Color;
    
            public ColorPickerArgs(Color c)
            {
                this.Color = c;
            }
    
            public Color ColorPicked
            {
                get { return Color; }
            }
        }
    

    When you drop the custom control on your form after building the solution, you'll find 3 additional properties; UseCustom, UseWeb, UseSystem. Set those to true or false to either hide or show the tab. Also, pay attention to the Infragistics class references in the custom control to make sure you have them in your references of the project.

    Edit Note: There is also a Color property that allows you to grab the picked color, and also a ColorPicked event that has a ColorPicked property in the args that contains the color picked.

Reply Children
No Data