Colour Picker Event Handling

Hey,

Got a bit of a question (which relates to the GH_ColourPicker and my learning of Event Handling. I want to store the colour that is picked into a class variable called ‘colour’. I’ve tried a few things, but nothing seems to get it to pass it to the class variable. Any help would be much appreciated.

System.Drawing.Color colour;

    protected override void AppendAdditionalComponentMenuItems(System.Windows.Forms.ToolStripDropDown menu)
    {
        // Append the item to the menu, making sure it's always enabled and checked if Absolute is True.
        Grasshopper.GUI.GH_ColourPicker fade_colour = GH_DocumentObject.Menu_AppendColourPicker(menu, colour, colour_changed);
    }


    private void colour_changed(object sender, EventArgs e)
    {
        colour = (sender as Grasshopper.GUI.GH_ColourPicker).Colour;
    }

Can you post a screenshot of what it looks like with your code?
Just by reading it I can only see two possible issues. The component itself will be a GH_DocumentObject so you can directly call Menu_AppendColourPicker(). You may also want to expire solution in the event handler.

Grasshopper.GUI.GH_ColourPicker fade_colour = GH_DocumentObject. Menu_AppendColourPicker(menu, colour, colour_changed);

Hey Will,

Thanks for your help, yep calling ExpireSolution() fixed it!

You are a legend!