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

  • Home
  • SEARCH
  • 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 currently have a simple color picker that loads in a color gradient image
I have in my application resources file brush: <SolidColorBrush x:Key=MainColor Color=#FF15428B /> I want
I have been looking at how to use an NSColorWell in my app, but
I'm building a site where I want users to be able to change the
I've looked everywhere and I can't seem to find a solution that works... I'm
I have a div with an onmousedown event, but it is triggering when I
I might be going about this all wrong, so hopefully someone will tell me
I know this is probably something so simple that I am just not able
I'm having some difficulty with managing an administration page, where I constantly get an
I need your suggestions how to organize and make a nice, graphical user interface.

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.