Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help loading form, progress bar and button

Help loading form, progress bar and button

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave McCool
    wrote on last edited by
    #1

    I have a progress bar on my first form (first form you see when application loads). What I want to happen is when the form opens for the progress bar to go up 10 every second until it gets to its maximum value of 100, stop and stay at maximum value then enable a button which is disabled. Code on form load:

    Timer time1 = new Timer();
    time1.Interval = 10;
    time1.Tick += new EventHandler(timer1_Tick);
    time1.Start();

    Code on timer tick:

    progressBar1.Value += 1;
    timer1.Stop();

    Now the problem with this code, I get an error because the progress bar tries to go 1 higher than its maximum value and I can't figure how to get the progress bar to stop trying to go higher when its at its maximum value. I am not sure where to put the button enable code since there is something I am doing wrong here. Next I have another button that when clicked I want it to close the form and open another form. I don't want the form to hide when closed but exit the form completly, but putting form1.close (); it won't work as its my first form, the whole app just exits. What should I do?

    In the end we're all just the same

    L 1 Reply Last reply
    0
    • D Dave McCool

      I have a progress bar on my first form (first form you see when application loads). What I want to happen is when the form opens for the progress bar to go up 10 every second until it gets to its maximum value of 100, stop and stay at maximum value then enable a button which is disabled. Code on form load:

      Timer time1 = new Timer();
      time1.Interval = 10;
      time1.Tick += new EventHandler(timer1_Tick);
      time1.Start();

      Code on timer tick:

      progressBar1.Value += 1;
      timer1.Stop();

      Now the problem with this code, I get an error because the progress bar tries to go 1 higher than its maximum value and I can't figure how to get the progress bar to stop trying to go higher when its at its maximum value. I am not sure where to put the button enable code since there is something I am doing wrong here. Next I have another button that when clicked I want it to close the form and open another form. I don't want the form to hide when closed but exit the form completly, but putting form1.close (); it won't work as its my first form, the whole app just exits. What should I do?

      In the end we're all just the same

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      :confused:

      Dave McCool wrote:

      time1.Interval = 10;

      that is 10 milliseconds.

      Dave McCool wrote:

      progressBar1.Value += 1;
      timer1.Stop();

      so it will increment once, then the timer stops? You need some conditional code. Maybe test whether incrementing the progress bar would overflow, and if so stop the timer and change the button state. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      D 1 Reply Last reply
      0
      • L Luc Pattyn

        :confused:

        Dave McCool wrote:

        time1.Interval = 10;

        that is 10 milliseconds.

        Dave McCool wrote:

        progressBar1.Value += 1;
        timer1.Stop();

        so it will increment once, then the timer stops? You need some conditional code. Maybe test whether incrementing the progress bar would overflow, and if so stop the timer and change the button state. :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        D Offline
        D Offline
        Dave McCool
        wrote on last edited by
        #3

        Hi, 10 milliseconds, yes that's what I meant, I wanted the progress bar to go up 1 every 10 milliseconds until it hit the maximum value then stop, btu the timer stop isn't working. The timer doesn't appear to stop, or I think the way I have the code, its won't stop as it trying to go one higher than the maximum value of the progress bar and not stopping when it gets to maximum value. I just was not sure where to put the timer stop code so that the timer would stop when progress bar gets to its maximum value, I think this way it will stop when it gets one over its maximum value, which it can't do.

        In the end we're all just the same

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups