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. Progress Bar

Progress Bar

Scheduled Pinned Locked Moved C#
helpquestionannouncement
5 Posts 3 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.
  • S Offline
    S Offline
    Sean89
    wrote on last edited by
    #1

    I have the following callback function which I am using to update a progress bar. The only problem is, when I change the value of the progress bar, the bar doesnt change:confused: It just shoots to 100 when it is done. I have tried using Application.DoEvents(); .

        private Int32 CopyInProgress(uint TotalFileSize, uint BytesTransfered, uint StreamSize, uint StreamBytesTransfered, uint DwStreamNumber, long dwCallbackReason, long hSourceFile, long hDestinationFile, long lpData)
        {
            float t = TotalFileSize;
    		float bt = StreamSize;
    			
    	    int nPercent = (int)(bt/t)\* 100;
    
            percentComp.Text = nPercent.ToString() + "%";
    
            progressBar.Value = nPercent;
           
            Application.DoEvents();
    
            return PROGRESS\_CONTINUE;
        }
    

    Any ideas why this is happening?


    Sean :)

    P 1 Reply Last reply
    0
    • S Sean89

      I have the following callback function which I am using to update a progress bar. The only problem is, when I change the value of the progress bar, the bar doesnt change:confused: It just shoots to 100 when it is done. I have tried using Application.DoEvents(); .

          private Int32 CopyInProgress(uint TotalFileSize, uint BytesTransfered, uint StreamSize, uint StreamBytesTransfered, uint DwStreamNumber, long dwCallbackReason, long hSourceFile, long hDestinationFile, long lpData)
          {
              float t = TotalFileSize;
      		float bt = StreamSize;
      			
      	    int nPercent = (int)(bt/t)\* 100;
      
              percentComp.Text = nPercent.ToString() + "%";
      
              progressBar.Value = nPercent;
             
              Application.DoEvents();
      
              return PROGRESS\_CONTINUE;
          }
      

      Any ideas why this is happening?


      Sean :)

      P Offline
      P Offline
      Phil C
      wrote on last edited by
      #2

      Yup, I got an idea. You are converting a float (bt/t) into an int...then multiplying it by 100. By definition, when you make it an int in this manner the answer can only be 0 or 100 and nothing in between. try changing it to: int nPercent = (int)(bt/t*100); :)

      R 1 Reply Last reply
      0
      • P Phil C

        Yup, I got an idea. You are converting a float (bt/t) into an int...then multiplying it by 100. By definition, when you make it an int in this manner the answer can only be 0 or 100 and nothing in between. try changing it to: int nPercent = (int)(bt/t*100); :)

        R Offline
        R Offline
        Rob Philpott
        wrote on last edited by
        #3

        Nicely spotted! I was trying to find a reason why the message couldn't have reached the control. Tuh! Regards, Rob Philpott.

        P 1 Reply Last reply
        0
        • R Rob Philpott

          Nicely spotted! I was trying to find a reason why the message couldn't have reached the control. Tuh! Regards, Rob Philpott.

          P Offline
          P Offline
          Phil C
          wrote on last edited by
          #4

          Not a problem. Even a crusty old C programmer gets to get one right once in a while. The rest of the time I'm generally walking around C# and .NET like a complete idiot because so many of the rules have been changed that there's not a lot of advantage to having programmed for 20+ years...LOL. Score: Cprogrammers = 1; WhizKids = INT_MAX; :)

          S 1 Reply Last reply
          0
          • P Phil C

            Not a problem. Even a crusty old C programmer gets to get one right once in a while. The rest of the time I'm generally walking around C# and .NET like a complete idiot because so many of the rules have been changed that there's not a lot of advantage to having programmed for 20+ years...LOL. Score: Cprogrammers = 1; WhizKids = INT_MAX; :)

            S Offline
            S Offline
            Sean89
            wrote on last edited by
            #5

            Hey thanks a lot ;)


            Sean :)

            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