Jump to content

Progress Bar Issues

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Umbrageous

Umbrageous

    Newbie

  • Members
  • PipPip
  • 17 posts
I always fail to do my laundry because i get sucked into my computer so i thoughtd I'd program something to help me out a little bit. yet I cant get the progress bars to run for anything.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Laundry_Helper
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Enabled = true;
            timer2.Start();
            button2.Enabled = false;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Start();
            button1.Enabled = false;
        }

        private void progressBar2_Click(object sender, EventArgs e)
        {
            if (progressBar2.Value == 3600000)
            {
                System.Media.SystemSounds.Beep.Play();
                progressBar2.Value = 0;
                timer2.Enabled = false;
                timer2.Stop();
                button2.Enabled = true;

            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Maximum = 1800000;
            progressBar1.Minimum = 0;
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            progressBar2.Maximum = 3600000;
            progressBar2.Minimum = 0;
        }

        private void progressBar1_Click(object sender, EventArgs e)
        {
            if (progressBar1.Value == 1800000)
            {
                System.Media.SystemSounds.Beep.Play();
                progressBar1.Value = 0;
                timer1.Enabled = false;
                timer1.Stop();
                button1.Enabled = true;
            }

        }
    }
}
And the Timers go in milliseconds right?

There are two progress bars One for The Washing Cycle one for the Drying
And Two Timers for each.

#2
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
This is an example how it should be done. If you have any questions regarding this solution, feel free to ask.


using System;

using System.Windows.Forms;


namespace Laundry_Helper

{

    public partial class Form1 : Form

    {

        private const int washingTime = 3600; //set our washing time in seconds

        private const int dryingTime = 1800; //set our drying time in seconds


        private double washingDuration; //this variable will hold the washing duration time

        private double dryingDuration; //this variable will hold the drying duration time


        public Form1()

        {

            InitializeComponent();

            InitCustomComponents(); //Let's initialize our custom settings

        }


        private void InitCustomComponents()

        {

            pbWashing.Minimum = 0;

            pbWashing.Maximum = 100;


            pbDrying.Minimum = 0;

            pbDrying.Maximum = 100;


            tmrWashing.Interval = 1000; //tick interval should be 1 second

            tmrDrying.Interval = 1000; //tick interval should be 1 second

        }


        private void tmrWashing_Tick(object sender, EventArgs e)

        {

            if (pbWashing.Value < 100) //if progress is not 100% complete

            {

                washingDuration += (100f / washingTime); //increase wasing duration

                pbWashing.Value = (int)washingDuration; //convert wasing duration to int and set pb value

            }

            else

            {

                pbWashing.Value = 100; //set pb value to 100%

                System.Media.SystemSounds.Beep.Play(); //Play the beep sound

                tmrWashing.Enabled = false; //stop the timer

                btnStartWashing.Enabled = true; //Enabled 'Start wasing' button

            }

        }


        private void tmrDrying_Tick(object sender, EventArgs e)

        {

            if (pbDrying.Value < 100) //if progress is not 100% complete

            {

                dryingDuration += (100f / dryingTime); //increase drying duration

                pbDrying.Value = (int)dryingDuration; //convert drying duration to int and set pb value

            }

            else

            {

                pbDrying.Value = 100; //set pb value to 100%

                System.Media.SystemSounds.Beep.Play(); //Play the beep sound

                tmrDrying.Enabled = false; //stop the timer

                btnStartDrying.Enabled = true; //Enabled 'Start drying' button

            }

        }


        private void btnStartWashing_Click(object sender, EventArgs e)

        {

            pbWashing.Value = 0; //reset progress bar value to zero

            washingDuration = 0; //reset washing duration to zero

            tmrWashing.Enabled = true; //start the timer

            btnStartWashing.Enabled = false; //disable the 'Start washing' button

        }


        private void btnStartDrying_Click(object sender, EventArgs e)

        {

            pbDrying.Value = 0; //reset progress bar value to zero

            dryingDuration = 0; //reset drying duration to zero

            tmrDrying.Enabled = true; //start the timer

            btnStartDrying.Enabled = false; //disable the 'Start drying' button

        }

    }

}