13 Replies - 883 Views - Last Post: 13 October 2012 - 01:44 PM Rate Topic: -----

#1 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

how to get state of the timer

Posted 12 October 2012 - 03:34 PM

Is it possible to get the state of the timer, kinda like the Timer.Started

I need this functionality
if(Timer.Started)
 Timer.Stop();
else()
Timer.Start();


Is This A Good Question/Topic? 0
  • +

Replies To: how to get state of the timer

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,645
  • Joined: 02-June 10

Re: how to get state of the timer

Posted 12 October 2012 - 03:40 PM

Look at the MSDN for timer
http://msdn.microsof...orms.timer.aspx


Read the properties list.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#3 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

Re: how to get state of the timer

Posted 12 October 2012 - 03:48 PM

Thanks, i wasn't looking at Winforms timer. I'm getting sleepy :sleep1:
It's 1 AM here.

This post has been edited by Michael26: 12 October 2012 - 03:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,645
  • Joined: 02-June 10

Re: how to get state of the timer

Posted 12 October 2012 - 03:53 PM

Well... We could play 'guess and by golly'... Or you could tell us what timer you *are* talking about.
Was This Post Helpful? 0
  • +
  • -

#5 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

Re: how to get state of the timer

Posted 12 October 2012 - 03:56 PM

Next time i'll be more specific.
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,645
  • Joined: 02-June 10

Re: how to get state of the timer

Posted 12 October 2012 - 03:58 PM

Oh kay. So you don't want to tell us now? You've worked it out, this problem is resolved and we can close this topic?
Was This Post Helpful? 0
  • +
  • -

#7 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

Re: how to get state of the timer

Posted 12 October 2012 - 04:06 PM

No, it isn't. I'll update with the question.
Was This Post Helpful? 0
  • +
  • -

#8 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

Re: how to get state of the timer

Posted 12 October 2012 - 04:14 PM

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Playing_with_words
{
    public partial class Form1 : Form
    {
        
        // This has the list of char of all letter of the alphabet in uppercase
        List<char> bigLettersOfAlphabet = new List<char>();       
        int counter = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
            for (int i = 65; i <= 90; i++)
            {
                char c = Convert.ToChar(i);
                bigLettersOfAlphabet.Add(c);
            }                       
        }
        /// <summary>
        /// For every tick i assaign the next letter to the button.text
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            LoopLetters(bigLettersOfAlphabet[counter]);
        }
        
        private void LoopLetters(char p) 
        {
            char letter = bigLettersOfAlphabet[counter];
            foreach (Control ctrl in Controls)
            {
                if (ctrl is Button)
                {
                    ((Button)(ctrl)).Text = letter.ToString();
                }
            }
            
            counter++;
            if (counter == bigLettersOfAlphabet.Count)
            {
                counter = 0;
                LoopLetters(bigLettersOfAlphabet[counter]); //Recursion is only for looping over and over untill the timer.stop is called
            }
        }

        private void StopLetter(object sender, EventArgs e)
        {
                        string btn = ((Button)sender).Text;            
            ((Button) sender).Text = btn;
            
        }        
    }
}



The StopLetter is assigned to every button.Click event, what i want is for every click to stop the timer for each individual control

This post has been edited by Michael26: 12 October 2012 - 04:15 PM

Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,645
  • Joined: 02-June 10

Re: how to get state of the timer

Posted 12 October 2012 - 04:24 PM

Quote

i wasn't looking at Winforms timer


Sure looks like you're working with a Windows forms timer to me.

You're working on a WinForms project, and it looks like you drag-n-dropped a timer from the toolbox to it. So that would be a WinForms timer. If you've done some thing more exotic you need to tell us.



Quote

03 using System.Windows.Forms;

21 timer1.Start();

Was This Post Helpful? 0
  • +
  • -

#10 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

Re: how to get state of the timer

Posted 12 October 2012 - 04:33 PM

Quote

If you've done some thing more exotic you need to tell us.


I just did, i posted the code and the question.
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,645
  • Joined: 02-June 10

Re: how to get state of the timer

Posted 12 October 2012 - 04:38 PM

I'm about to loose my patience, so this is the last post I make trying to clarify this. Take your time formulating a response.

In post 3 you said you are not looking at using WinForms timer.
In your code it sure looks like you are using WinForms timer.

In post 2 I showed you the property you asked about that would let you know if the timer was already running: .Enabled

The code you posted makes no effort to use that property.

So... Specifically... Which timer do you think you are using?
What are you asking from us? What do you need help with? (Note: we aren't writing your code for you so don't ask.)
Was This Post Helpful? 0
  • +
  • -

#12 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

Re: how to get state of the timer

Posted 12 October 2012 - 04:52 PM

I'm trying to use Winforms timer. In post #3 i was trying to say i was looking at Timers timer not winforms timer(it was a mistake on my part)

You can close this thread,(if you want) i'll try another time.
I didn't ask for code, just a tip or an advice.

This post has been edited by Michael26: 12 October 2012 - 04:55 PM

Was This Post Helpful? 0
  • +
  • -

#13 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 349
  • View blog
  • Posts: 1,498
  • Joined: 08-April 09

Re: how to get state of the timer

Posted 13 October 2012 - 06:32 AM

Quote

The code you posted makes no effort to use that property.

Here tlhIn`toq

if (timer1.Enabled)
            {
                timer1.Stop();
            }
            else
            {
                timer1.Start();
            }

I have (for example) 3 buttons control on form, how can an Click event respond to each of the controls individually? (refer to the code i posted in #8).
So far i have is when the click event is executed ALL buttons stop the timer, i need to stop buttons one at the time.

This post has been edited by Michael26: 13 October 2012 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

#14 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,645
  • Joined: 02-June 10

Re: how to get state of the timer

Posted 13 October 2012 - 01:44 PM

I'm done. Providing one block of 8 lines, completely out of context, that aren't incorporated in your larger block of code is meaningless.

Quote

i need to stop buttons one at the time.

This doesn't even make sense. You don't stop a button. I'm sort of getting the impression you might have more than one timer going and need to stop each timer one at a time. Or you might mean you need to get the 'lap time' like on a stop watch with each button. But really, I'm only guessing because you can't seem to actually explain yourself.

I've come to realize you're not asking how to recognize if a timer is going or not - you're asking someone to either do your engineering for you, or do your coding for you.

I'm sorry if you can't figure out how to design your application. But the job title is "software engineer" - meaning that half the job is the engineering part. Maybe you're just rushing to start designing before you are ready. You might consider doing a lot more tutorials. Read some C# recipe books to take in better design ideas. Troll the net for open-source projects you can dissect and learn from. Hell, I've got some tutorials right here on DIC that are for this purpose.

Please - read the homework help article linked in my signature block. I think you would benefit from more planning BEFORE you start banging on the keyboard. But as for this thread, I've reached my saturation point. There's nothing more I can make out and nothing more I can do for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1