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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Progress Bar

Progress Bar

Scheduled Pinned Locked Moved C#
graphicsquestion
4 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.
  • S Offline
    S Offline
    S K Y
    wrote on last edited by
    #1

    Hi, I want to do my progress bar in to pop up progress bar. i mean when i load something i want to pop up progress bar while progressing only. how can i do that. i wrote the coding for static progress bar. i mean drag & drop progrss bar from tool in to my form.

    ProgressBar ProBar = new ProgressBar();

        private void import(object sender, EventArgs e)
        {
            if (listView1.Items.Count == 0)
            {
                ImageList imageList = new ImageList();
                imageList.ImageSize = new Size(100, 80);
                imageList.ColorDepth = ColorDepth.Depth32Bit;
                this.ProBar = new System.Windows.Forms.ProgressBar();
                this.ProBar.TabIndex = 0;
                this.ProBar.Maximum = dlg.FileNames.Length;
                this.ProBar.Minimum = 1;
                this.ProBar.Step = 1;
                
                foreach (string path in dlg.FileNames)
                {
                    FileInfo fileInfo = new FileInfo(path);
                    listView1.Items.Add(fileInfo.Name);
                    imageList.Images.Add(Bitmap.FromFile(path));                    
                    ProBar.PerformStep();
                }
    

    A S E L A

    N 1 Reply Last reply
    0
    • S S K Y

      Hi, I want to do my progress bar in to pop up progress bar. i mean when i load something i want to pop up progress bar while progressing only. how can i do that. i wrote the coding for static progress bar. i mean drag & drop progrss bar from tool in to my form.

      ProgressBar ProBar = new ProgressBar();

          private void import(object sender, EventArgs e)
          {
              if (listView1.Items.Count == 0)
              {
                  ImageList imageList = new ImageList();
                  imageList.ImageSize = new Size(100, 80);
                  imageList.ColorDepth = ColorDepth.Depth32Bit;
                  this.ProBar = new System.Windows.Forms.ProgressBar();
                  this.ProBar.TabIndex = 0;
                  this.ProBar.Maximum = dlg.FileNames.Length;
                  this.ProBar.Minimum = 1;
                  this.ProBar.Step = 1;
                  
                  foreach (string path in dlg.FileNames)
                  {
                      FileInfo fileInfo = new FileInfo(path);
                      listView1.Items.Add(fileInfo.Name);
                      imageList.Images.Add(Bitmap.FromFile(path));                    
                      ProBar.PerformStep();
                  }
      

      A S E L A

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      I guess I have already answered this few days back. To reiterate, you need to create a new form and place progress bar in that. Create methods in that form which updates the progress bar. You can call this method from your form whenever a progress happens. :)

      Navaneeth How to use google | Ask smart questions

      S 1 Reply Last reply
      0
      • N N a v a n e e t h

        I guess I have already answered this few days back. To reiterate, you need to create a new form and place progress bar in that. Create methods in that form which updates the progress bar. You can call this method from your form whenever a progress happens. :)

        Navaneeth How to use google | Ask smart questions

        S Offline
        S Offline
        S K Y
        wrote on last edited by
        #3

        Hi, thanks a lot for your reply, may i know some thing... how about if i creat a method in my exicting form and cal that method when i need progress bar.is this posible to do?? i tried this out but by this way i couldn't get progress bar like message box....

        A S E L A

        N 1 Reply Last reply
        0
        • S S K Y

          Hi, thanks a lot for your reply, may i know some thing... how about if i creat a method in my exicting form and cal that method when i need progress bar.is this posible to do?? i tried this out but by this way i couldn't get progress bar like message box....

          A S E L A

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          S K Y wrote:

          i couldn't get progress bar like message box..

          What do you mean by progress bar like message box? A modal progress bar which will not allow to click on other forms when progress is shown? If yes, here is a method 1 - Create a new form say Progress 2 - Add a progress bar say "pb" to this form. 3 - Create a delegate in this form which will call back the method to execute from the progress window. Refer the following code

          // use this class to interact with progress form your form
          public class ProgressEventArgs
          {
          ProgressBar pb;
          Form form;

          public ProgressEventArgs(ProgressBar pb, Form form)
          {
              this.pb = pb;
              this.form = form;
          }
          
          public void PerformProgress(int value)
          {
              form.BeginInvoke((MethodInvoker)delegate
              {
                  this.pb.Value = value;
              });
          }
          
          public void StopProgress()
          {
              form.BeginInvoke((MethodInvoker)delegate
              {
                  form.Close();
              });
          }
          

          }

          public delegate void WorkStartedHandler(ProgressEventArgs pe);

          // your progress form
          public partial class Progress : Form
          {
          WorkStartedHandler method;
          public Progress()
          {
          InitializeComponent();
          }

          public void ShowProgress(int minimum, int maximum, WorkStartedHandler method)
          {
              pb.Minimum = minimum;
              pb.Maximum = maximum;
              this.method = method;
              new Thread(DoWork).Start();
              this.ShowDialog();
          }
          
          void DoWork()
          {
              method(new ProgressEventArgs(this.pb, this));
          }
          

          }

          The above code is simple and self explaining. You can use this like

          private void import(object sender, EventArgs e)
          {
          if (listView1.Items.Count == 0)
          {
          Progress p = new Progress();
          p.ShowProgress(1, dlg.FileNames.Length, DoWork);
          }
          }

          void DoWork(ProgressEventArgs pe)
          {
          int i = 0;
          foreach (string path in dlg.FileNames)
          {
          .............
          .............
          ++i;
          pe.PerformProgress(i);
          }
          pe.StopProgress();
          }

          I wrote the above code in CP editor directly, so expect some compile time errors. :)

          Navaneeth How to use google |

          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