|
-
Oct 20th, 2010, 10:17 PM
#1
Thread Starter
Hyperactive Member
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!
-
Oct 20th, 2010, 10:29 PM
#2
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.
-
Oct 20th, 2010, 10:39 PM
#3
Thread Starter
Hyperactive Member
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!
-
Oct 20th, 2010, 10:48 PM
#4
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?
-
Oct 20th, 2010, 10:53 PM
#5
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.
-
Oct 20th, 2010, 11:45 PM
#6
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
-
Oct 20th, 2010, 11:57 PM
#7
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
-
Oct 20th, 2010, 11:58 PM
#8
Re: Progress Meter
 Originally Posted by kaliman79912
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|