Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Color Calculation

Color Calculation

Scheduled Pinned Locked Moved C#
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RadioButton
    wrote on last edited by
    #1

    Hello, I want to return a string color based on these 4 calculations. X = 25% 5.0% >= X >= -5.0% blue +15.0% >= X > +5.0% and -5.0% > X >= -15.0% yellow +25.0% >= X > +15.0% and -15.0% > X >= -25% green X > +25.0% and X < -25.0% red I am having trouble forming the logic. Thank you for the help.

    RaviBeeR 1 Reply Last reply
    0
    • R RadioButton

      Hello, I want to return a string color based on these 4 calculations. X = 25% 5.0% >= X >= -5.0% blue +15.0% >= X > +5.0% and -5.0% > X >= -15.0% yellow +25.0% >= X > +15.0% and -15.0% > X >= -25% green X > +25.0% and X < -25.0% red I am having trouble forming the logic. Thank you for the help.

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      Off the top of my head - untested! :)

      int x = 25;
      Color c = GetColor (x);

      public Color GetColor
      (int x)
      {
      if ((x <= 5) && (x >= -5))
      return Color.Blue;
      if ((x <= 15) && (x >= -15))
      return Color.Yellow;
      if ((x <= 25) && (x >= -25))
      return Color.Green;
      return Color.Red;
      }

      /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups