Results 1 to 8 of 8

Thread: Progress Meter

  1. #1

    Thread Starter
    Hyperactive Member Art W.'s Avatar
    Join Date
    Apr 2002
    Location
    In My Own Little World, But that’s OK because they know me there!
    Posts
    271

    Progress Meter

    Hello Everyone:

    I am trying to use a power meter to track the progress of my program; this will be for my use only and will be removed later. I would also like to display the percentage run in the meter. I already know what the start and end points will be for the meter. What do I need to search for? I have been looking and haven’t been able to find anything that suits my needs yet. I am running VB 2005.

    Thanks

    Art W.
    SLEEP: A Totally Inadequate Substation For Caffeine!

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

    Re: Progress Meter

    I'm not sure what you're actually asking for. Are you saying that you want a dial-type progress indicator, like a speedometer in a car? Your first sentence makes it sound like you have external hardware that you want to use to indicate progress, but the second sentence suggests that is not the case.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Art W.'s Avatar
    Join Date
    Apr 2002
    Location
    In My Own Little World, But that’s OK because they know me there!
    Posts
    271

    Re: Progress Meter

    Hi,

    No I want a bar type meter that progresses as the program progresses.

    Thanks
    SLEEP: A Totally Inadequate Substation For Caffeine!

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

    Re: Progress Meter

    I was assuming that you were aware of the ProgressBar control but were not using it for a specific reason, but now I'm not so sure. There's a ProgressBar control in your VS Toolbox. Have you tried that?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: Progress Meter

    Ah, I guess that the requirement to have the percentage displayed in control would preclude the standard ProgressBar. For future reference, using terms like "power meter" is only going to confuse people because you're not measuring any power. All you had to say was you want a control like the ProgressBar but one that can display the percentage on the bar.

    I'm quite sure that there are numerous examples of just that around already. If I was looking, I would just search for "custom progressbar .net". Seems the obvious choice to me. That said, it's not too hard to whip up something yourself with a bit of GDI+. Example code to follow.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Progress Meter

    I dont think you need to go to any trouble. I understand you are doing this only in the development stage and would be removed later. So, put the progressBar control, which is very straight forward and a separate label with the percentage text. It does not need to be really neat if you are not using it in the end product.

    You just need to put the ProgressBar control on your form and set the minimum and maximum values and stretch it as you need. then in the program you control the value property. that's it.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

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

    Re: Progress Meter

    I'm sure you could go with GDI+ but I decided to use a Panel and two Labels. I created it in VS 2010 so I've provided code only. If you create a new project and add a Button, a Panel, two Labels and a BackgroundWorker and then the following code, the whole thing should work. This is just one way you could do it. There are various others, including putting this functionality into a UserControl.
    Code:
    Imports System.Threading
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Label2.AutoSize = False
            Me.Label2.SetBounds(10, 100, 200, 25)
            Me.Label2.BackColor = SystemColors.ControlDark
            Me.Label2.ForeColor = SystemColors.ControlText
            Me.Label2.TextAlign = ContentAlignment.MiddleCenter
            Me.Label2.BringToFront()
    
            Me.Label1.AutoSize = False
            Me.Label1.Parent = Me.Panel1
            Me.Label1.SetBounds(0, 0, 200, 25)
            Me.Label1.BackColor = SystemColors.Highlight
            Me.Label1.ForeColor = SystemColors.HighlightText
            Me.Label1.TextAlign = ContentAlignment.MiddleCenter
            Me.Panel1.SetBounds(10, 100, 0, 25)
            Me.Panel1.BringToFront()
    
            Me.BackgroundWorker1.WorkerReportsProgress = True
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Not Me.BackgroundWorker1.IsBusy Then
                Me.SetProgress(0)
                Me.BackgroundWorker1.RunWorkerAsync()
            End If
        End Sub
    
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            For count = 0 To 100
                Me.BackgroundWorker1.ReportProgress(count)
                Console.WriteLine("count = " & count)
                Thread.Sleep(500)
            Next
        End Sub
    
        Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
            Me.SetProgress(e.ProgressPercentage)
        End Sub
    
        Private Sub SetProgress(ByVal progress As Integer)
            Me.Label1.Text = progress & " %"
            Me.Label2.Text = progress & " %"
            Me.Panel1.Width = progress * 2
        End Sub
    End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: Progress Meter

    Quote Originally Posted by kaliman79912 View Post
    I dont think you need to go to any trouble. I understand you are doing this only in the development stage and would be removed later.
    That's a point. I forgot that part. Now I've gone to some trouble.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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