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. A little problem

A little problem

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 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.
  • Z Offline
    Z Offline
    zeeShan anSari
    wrote on last edited by
    #1

    hi, for(i=0;i<4;i++) { if(i==0){button.Color=Color.Red;} else if(i==1){button.Color=Color.Blue;} else if(i==2){button.Color=Color.Black;}} else if(i==3){button.Color=Color.Yellow;}} } why button color is not change?i want change the button color according to the if-else conditions.

    I AM WORKING ON "PLOTTER ROBOT"(FYP).

    G R 2 Replies Last reply
    0
    • Z zeeShan anSari

      hi, for(i=0;i<4;i++) { if(i==0){button.Color=Color.Red;} else if(i==1){button.Color=Color.Blue;} else if(i==2){button.Color=Color.Black;}} else if(i==3){button.Color=Color.Yellow;}} } why button color is not change?i want change the button color according to the if-else conditions.

      I AM WORKING ON "PLOTTER ROBOT"(FYP).

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Each color change causes a message that will be send to the button so that it will change it's color. The messages are queued and are all executed when you return the control to the message pump (when you exit the method). You can use the DoEvents method to make the message pump handle the messages, and a delay so that you have time to actually see the change: foreach (Color c in new Color[] { Color.Red, Color.Blue, Color.Black, Color.Yellow}) { button.Color = c; DoEvents(); Thread.Sleep(500); } However, if you really want to do something like this, you should use a timer instead.

      Experience is the sum of all the mistakes you have done.

      1 Reply Last reply
      0
      • Z zeeShan anSari

        hi, for(i=0;i<4;i++) { if(i==0){button.Color=Color.Red;} else if(i==1){button.Color=Color.Blue;} else if(i==2){button.Color=Color.Black;}} else if(i==3){button.Color=Color.Yellow;}} } why button color is not change?i want change the button color according to the if-else conditions.

        I AM WORKING ON "PLOTTER ROBOT"(FYP).

        R Offline
        R Offline
        Rich Insley
        wrote on last edited by
        #3

        That'll just make your button yellow every time. Get rid of the for statement.

        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