CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Oct 2008
    Posts
    26

    Traffic Lights c#

    I am trying to create a set of traffic lights using visual c#, my problem is how to implement a timer between each light. I have 3 traffic lights and 2 pedestrian lights. Any help on the timer folks.

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Traffic Lights c#

    Look at the Timer class.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Oct 2008
    Posts
    26

    Wink Re: Traffic Lights c#

    where's that Mr Vague

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Traffic Lights c#

    Quote Originally Posted by johnboy14
    where's that Mr Vague
    Did you ever consider a really radical approach of going to the MSDN site and typing in "Timer"...The very first hit is what you need.

    In case that is too difficult:http://msdn.microsoft.com/en-us/libr...rms.timer.aspx
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Jul 2008
    Posts
    169

    Re: Traffic Lights c#

    LOL You guys crack me up!

  6. #6
    Join Date
    Oct 2008
    Posts
    26

    Re: Traffic Lights c#

    very useful, I am new to c# so all and visual c# so I ain't quite up todate on all the sites and best places for different stuff. Thanks anyway.

  7. #7
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Traffic Lights c#

    Quote Originally Posted by johnboy14
    very useful, I am new to c# so all and visual c# so I ain't quite up todate on all the sites and best places for different stuff. Thanks anyway.
    maybe you should also try to use the little known search site called Google. a simple search for "c# timers" would have netted you plenty of results.

  8. #8
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Traffic Lights c#

    msdn.microsoft.com is the official site for any Microsoft product related questions.

    google.com is also a useful resource, but one needs to be careful since the results can come from "anyone". There is alot of incorrect material on the internet, and much of the .Net postings contain incorrect or sub-optimal information.

    I usually recommmend starting with msdn then google if necessary. If you find something that looks good on google, you will have specific keywords that you can use to confirm the information back on msdn.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  9. #9
    Join Date
    Oct 2008
    Posts
    26

    Re: Traffic Lights c#

    Would I declare the timer before the main or as soon as I enter the main.

    You see I have a Button that activates the lights, I want it to wait 5 seconds then give me an amber light.

  10. #10
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Traffic Lights c#

    You "Declare" the timer by dragging it from the toolbox onto your form. You can initialize the duration in the properties window, or in code. You can start and stop the timer with the enabled property. You write an event handler which is triggered when the timer expires.

    Did you download and step through the available samples?
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  11. #11
    Join Date
    Oct 2008
    Posts
    26

    Re: Traffic Lights c#

    bits of it, I am familar with declaring variables and methods etc. but I programmed a set of traffic lights with an AVR board once in C but low level stuff to be honest. I'll read through them,

    p.s I was unaware that there was a timer on visual c#, so I could drag and drop. I can't seem to find it on my toobar though.
    Last edited by johnboy14; October 5th, 2008 at 12:14 PM.

  12. #12
    Join Date
    Oct 2008
    Posts
    26

    Re: Traffic Lights c#

    In all honesty I'm not sure how to start.

    this below is my code for my start button, I set the timer to intervals of 5 seconds so am I free to place what what I want my lights to do now.

    private void button1_Click(object sender, System.EventArgs e)
    {
    timer1.Enabled = true
    Last edited by johnboy14; October 5th, 2008 at 12:48 PM.

  13. #13
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Traffic Lights c#

    Go back to design mode on your form. Select the timer. Select the Properties Windows. Switch to events view (looks like a lightning bolt). Double click on the event. This will add an empty routine to your code where you put the logic of what to do when the timer expires...

    I will ask one more time...
    Did you download and step through the available samples?
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  14. #14
    Join Date
    Oct 2008
    Posts
    26

    Re: Traffic Lights c#

    No I Did Not.

  15. #15
    Join Date
    Oct 2008
    Posts
    26

    Re: Traffic Lights c#

    I want it to just run in a loop. until the button is pressed

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured