CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 6 of 6

Thread: basic c# help

  1. #1
    Join Date
    Jun 2012
    Posts
    7

    Question basic c# help

    I'm trying to make this thing were when it is a certain time a label will turn red. So if lunch is 12:00-12:30 the label lunch will turn red for that time.

  2. #2
    Join Date
    Jan 2010
    Posts
    1,072

    Re: basic c# help

    You should be more precise with your questions. What are you having trouble with? Finding out the time? Changing the color of the label? Windows Forms? Changing the label color? All?
    You posted no code, so we can't use that to get a better picture of how to help you. Have you tried anything so far?

    For the time, check out the DateTime struct (scrol down for some examples). For the label color, change the ForeColor property of the label (assuming you're using Win Forms).

  3. #3
    Join Date
    Jun 2012
    Posts
    7

    Re: basic c# help

    finding the time and how to set the times

  4. #4
    Join Date
    Apr 2012
    Posts
    29

    Re: basic c# help

    Quote Originally Posted by orangelight View Post
    finding the time and how to set the times
    Please be more specific about your application and what you have done so far ?

  5. #5
    Join Date
    Jan 2010
    Posts
    1,072

    Re: basic c# help

    The DateTime structure has a static property Now which let's you get the current date and time. Once you obtain it, you can compare it to other values. Simply use two DateTime member variables in your form class to store the start time and the end time.
    Code:
    DateTime date1 = new DateTime(2012, 6, 25, 12, 0, 0);   //  6/25/2012 12:00:00  -- make sure it's a class member variable
    
    /* Parameters:
    
    year
        Type: System.Int32
        The year (1 through 9999).
    
    month
        Type: System.Int32
        The month (1 through 12).
    
    day
        Type: System.Int32
        The day (1 through the number of days in month).
    
    hour
        Type: System.Int32
        The hours (0 through 23).
    
    minute
        Type: System.Int32
        The minutes (0 through 59).
    
    second
        Type: System.Int32
        The seconds (0 through 59). 
    */
    You can use a timer that ticks at a certain interval to check the date & time with DateTime.Now. Drag the timer from the toolbox, and handle it's Tick event, by comparing the values stored with the value returned by DateTime.Now. Also, make sure that the timer is started once you run your app.
    You can ignore dates if they aren't needed, but you'll need to create a custom comparison method then.

  6. #6
    Join Date
    Jun 2012
    Posts
    7

    Re: basic c# help

    Thanks
    i got it to work!
    .NET4.0 / VS 2010

+ Reply to Thread

Bookmarks

Posting Permissions

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



HTML5 Development Center

Click Here to Expand Forum to Full Width