Results 1 to 6 of 6

Thread: progress bar [* Resovled *]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    progress bar [* Resovled *]

    Hello,

    I have a progress bar and i have the min set to 1 and the max set to 100. I want to be able to click on part of the progress bar and for the progress bar to go to the value that l click on in the progress bar.

    For example if the progress is on 10, and l click on the bar in the area of about 80, then the progress will go up to that value of 80.

    Many thanks in advance,

    Steve
    Last edited by steve_rm; Jul 7th, 2005 at 06:56 AM.
    steve

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: progress bar

    rate it if it works
    Code:
    private int clickedX;
    		private void progressBar1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    		{
    			clickedX = e.X;
    		}
    
    		private void progressBar1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    		{
    			double val = (double)clickedX/progressBar1.Width;
    			int range = progressBar1.Maximum - progressBar1.Minimum;
    
    			progressBar1.Value = (int)(val * range);
    		}
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: progress bar

    You should probably be using a TrackBar instead I think. Obviously it's up to you, but the ProgressBar doesn't accept user interaction easily because it's not supposed to be for that purpose.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: progress bar

    Hello,

    Thanks for your reply. I found another way to do the same thing. Here is the code on vbcity.com.

    Thanks

    VB Code:
    1. private void Form1_Load(object sender, System.EventArgs e)
    2.         {
    3.             this.progressBar1.MouseDown+=new MouseEventHandler(progressBar1_MouseDown);
    4.             this.progressBar1.MouseMove+=new MouseEventHandler(progressBar1_MouseMove);
    5.         }
    6.  
    7.         private void progressBar1_MouseDown(object sender, MouseEventArgs e)
    8.         {
    9.             this.AdjustProgress(e);
    10.         }
    11.  
    12.         private void progressBar1_MouseMove(object sender, MouseEventArgs e)
    13.         {
    14.             if (e.Button == MouseButtons.Left)
    15.             {
    16.                 this.AdjustProgress(e);
    17.             }
    18.         }
    19.  
    20.         private void AdjustProgress(MouseEventArgs e)
    21.         {
    22.             int x = e.X;
    23.             double d = ( ((double)x * (double)100.00) / (double)this.progressBar1.Width );
    24.             int value = Convert.ToInt32(System.Math.Ceiling((this.progressBar1.Maximum-this.progressBar1.Minimum)* d/100))+this.progressBar1.Minimum;
    25.             this.progressBar1.Value = System.Math.Max(this.progressBar1.Minimum, System.Math.Min(this.progressBar1.Maximum, value));
    26.         }
    steve

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: progress bar [* Resovled *]

    I take it we don't like the TrackBar then, that was purpose-built to provide this functionality.

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: progress bar [* Resovled *]

    same thing! wasting my time hehe
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width