hey i've created a counting mechanism project............in the attached project there is two labels label1 & label2.........on pressing the numberpad1 and numberpad3 keys, the count increments and decrements simultaneously which is been displayed in the corresponding labels (see the attached project)........

can anyone tell me an another method to do that by without using the timers..............

Edited 5 Years Ago by Jessurider: n/a

still, I dont understand your question.

what is it that you want to do without timers?

Edited 5 Years Ago by agugglez: n/a

you could set bools indicating the state of the keys then have one timer that checks the bools and makes the changes.

when video-streaming is activated the counting seems to be a little delay.........since because i'm using timers

int iNum = 0;

        bool bLeft = false;
        bool bRight = false;

        public MainForm()
        {
            InitializeComponent();
        }
        private void MainFormKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.NumPad3)
                bRight = false;
            if (e.KeyCode == Keys.NumPad1)
                bLeft = false;
        }

        private void MainFormKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.NumPad3)
                bRight = true;
            if (e.KeyCode == Keys.NumPad1)
                bLeft = true;
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            if (bRight)
                iNum++;
            if (bLeft)
                iNum--;
            if (iNum > 0)
            {
                label1.Text = iNum.ToString();
                label2.Text = "0";
            }
            else
            {
                label1.Text = "0";
                label2.Text = Math.Abs(iNum).ToString();
            }
        }

that will make the numbers better but i can figure out what you are trying to do with the camera

that works fine with a single timer.........

but can u please tell me why the counting seems a bit delay in between when we activate the videocapturing(see the attached PROJCT.zip)..............

is there any solution for that................

Edited 5 Years Ago by Jessurider: n/a

the counting is dealyed because the timer doesnt start right away after you set the timer.Enabled property to true. you have to call to it yourself the first time:

private void MainFormKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.NumPad3)
            {
                bRight = false;
                timer1.Stop();
            }
            if (e.KeyCode == Keys.NumPad1)
            {
                bLeft = false;
                timer1.Stop();
            }
        }

        private void MainFormKeyDown(object sender, KeyEventArgs e)
        {

            if (bRight || bLeft) return;

            if (e.KeyCode == Keys.NumPad3)
            {
                bRight = true;
                timer1.Start();
                ProcessTick();
            }
            if (e.KeyCode == Keys.NumPad1)
            {
                bLeft = true;
                timer1.Start();
                ProcessTick();
            }            
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            ProcessTick();
        }

        void ProcessTick() 
        {
            timer1.Interval = (200);

            if (bRight)
                iNum++;
            if (bLeft)
                iNum--;
            if (iNum > 0)
            {
                label1.Text = iNum.ToString();
                label2.Text = "0";
            }
            else
            {
                label1.Text = "0";
                label2.Text = Math.Abs(iNum).ToString();
            }
            //timer1.Enabled = false;
        }
This article has been dead for over six months. Start a new discussion instead.