Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:00:00+00:00 2026-05-18T00:00:00+00:00

So I have a color picker. Users can pick colors using RGB or HSB.

  • 0

So I have a color picker. Users can pick colors using RGB or HSB. There are sliders/properties for each value. When user sets Red for example, I will calculate HSB values to reflect new color value. When user sets Hue, the RGB value will be recalculated from the HSB values. But see there’s a loop there. When I set RGB it must recalculate HSB values, ok so far, but it also means that HSB values will change causing RGB values to be re updated again. I think this is where the problem is but how can I fix this?

UPDATE: One Possible Solution

One possible solution I used was flag, not very readable tho, but it works. Basically, when I set properties, I also set a flag to signify I am setting a value

public float Hue {
    get { return _hue; }
    set
    {
        if (_hue == value)
            return;
        CurrentlySetting = (CurrentlySetting.HasValue) ? CurrentlySetting : ColorType.HSB;
        _hue = value;
        NotifyPropertyChanged("Hue");
        NotifyPropertyChanged("Color");
        RecalculateRGB();
        CurrentlySetting = (CurrentlySetting == ColorType.HSB) ? null : CurrentlySetting;
    }
}

When I “Recalculate” Values, I check for that and ensure I am not currently setting them

protected void RecalculateRGB(Color color = new Color())
{
    if (CurrentlySetting == ColorType.RGB) // prevent stackoverflow
        return;

    if (color == new Color())
        color = HSBColorHelper.FromAHSB(255, Hue, Saturation, Brightness);
    Red = color.R;
    Green = color.G;
    Blue = color.B;
}

Not very straight forward, I still prefer @Marc Gravell’s, solution

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:00:01+00:00Added an answer on May 18, 2026 at 12:00 am

    I would have all the setters call into the same inner code:

    public byte R {
        get {return r;}
        set { SetRGB(value, G, B); }
    }
    public byte G {
        get {return g;}
        set { SetRGB(R, value, B); }
    }
    

    etc – and that inner SetRGB method only talks to the fields (not the properties), including any HSB fields you need; so no recursion. You might also want a SetHSB, obviously – again, setting all the fields (not calling into any of the property setters).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a color picker in my application that users can use to pick
I need to have a JQuery color Picker, where I can change the different
How do I add a color picker in Komodo? I need to have a
I have a Color companion object which holds a few useful colors, and I'd
I want to have different color to each side of a border in WPF
Im using the color picker here: http://blog.meta100.com/post/600571131/mcolorpicker Im using code shown in example 3.
I want to be able to choose three differents colors from a color picker.
I have a question of VB event handler and color picker. Now I have
I am making a color picker. I have the following code: View controller.h: @interface
I have a shape on a background. I have one jQuery color picker to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.