Page 1 of 1

[ProgressBar movement] !

Posted: Mon Apr 09, 2012 12:08 am
by DreadNought
Okay,

I got bored, Just making a test application with VS2011 BETA.

This will increase based on mathematical calculations, I will actually make this fully random so no increase is the same, However I got bored, and thought I would share

Code:
Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int valInc = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            valInc = valInc * 2 + 1;
            int val = progressBar1.Value * valInc / 5 + 3;
            if (val > 100)
                progressBar1.Value = 100;
            else
                progressBar1.Value = val;
            timer1.Interval = timer1.Interval / 2;
            if (timer1.Interval <= 1000)
                timer1.Interval = 2000;
            if (progressBar1.Value > 20)
            {
                timer1.Interval = 3000;
            }
                if (progressBar1.Value >= 100)
                timer1.Stop();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = 3000;
            timer1.Enabled = true;
            timer1.Start();
        }
    }
}


Re: [ProgressBar movement] !

Posted: Mon Apr 09, 2012 7:52 am
by MrAksel
I'm sure this is something everyone will use :lol: Goood job!
But you know you don't need both timer1.Enabled = true and timer1.Start(); ? Its enough with one of them.

Re: [ProgressBar movement] !

Posted: Fri Apr 13, 2012 9:45 pm
by DreadNought
no I did not, but thankyou, I'm more of a threading guy :)

Without checking, I believe only the Start(); method will invoke Enabled to true automatically, but Enabled will not invoke Start()? I honestly don't know, I'm by no means a GUI Wiz.

Re: [ProgressBar movement] !

Posted: Sat Apr 14, 2012 1:19 pm
by M1z23R
If .start enables the timer why would enable invoke start ? It would go in circles and overload :D

Re: [ProgressBar movement] !

Posted: Sun Apr 15, 2012 8:46 pm
by DreadNought
That is why I said .Enabled probably doesn't invoke the start, but it wouldn't matter because they probably check if it's started already and disable the start method going twice.