# VBForums CodeBank > CodeBank - Visual Basic .NET >  Vista/7 Style Progress Bar

## Matchlighter

UPDATED: Go down to post 12 for updated version.

I thought I would post here about a new Vista Style Progress bar that I improved from an older creation be somebody else. The original can be found here. Basically I took the older one and added A Marquee feature, which I believe is not very common in progress bars. I also Added Thresholds That can be set to change the Color of the bar when it surpasses the Threshold. I also added some additional customization features to it. I also plan to add a Text Display on it (I was planning to do that in this version so the Properties are there, but not functional). I am also planning to have only segments of the bar change when it reaches a Threshold. So the Part before the Threshold will be that of the previous Threshold and that after the Threshold will be that of the Threshold. Please feel free to use this in your projects. I also included a sample in the zip. I hope you like it and feel free to leave any suggestions or comments. I tried to post this on codeproject but it got disapproved. (Any Suggestions on how to get an Article approved?)

Hope You Like It!  :Smilie: 
E

----------


## JuggaloBrotha

You should remove the bin and obj folders from the projects before zipping and attaching to posts.

----------


## Matchlighter

Ok, I just got rid of em. May I ask why I should be doing that?

E

----------


## si_the_geek

Those folders contain compiled files, which have two problems for things like this.

The first is the fact that it increases the download size significantly with no benefit - because people can easily re-make the files in a few seconds.

The other is that the compiled files could contain something malicious, such as if there is a virus on your computer that has infected them.

----------


## vixez

How do I add this to my project?
If I reference it it doesn't show upi nthe toolbox, when I add the class to my project I get



```
Type 'CollectionEditor' is not defined.
```

If I then comment it it goes away, but after debugging the form where I placed the progressbar gives an error.
I ignore and continue it and my form goes blank.

Am I doing something wrong?

----------


## Matchlighter

It does not work with .NET 4.0 if that is what you are using. I forgot to upload a fix to that. I will soon though. If you are not using .NET 4.0, add a reference to System.Design.

----------


## vixez

That didn't work.
I also got that error on your project.

I get this error when starting a new project and building after.
This shows after the build stops.




> Object of type 'WindowsApplication1.VistaStyleProgressBar.ThresholdItem[]' cannot be converted to type 'WindowsApplication1.VistaStyleProgressBar.ThresholdItem[]'.

----------


## Matchlighter

I will take a look at the code as soon as I am less busy. Sorry for the inconvenience.

----------


## BobbyP

Works fine for me and thanks for the nice progress bar


I have vs 2010 net 4

I created a new windows form project, targeted at net 3.5.  I added to the project an 'existing item' browsed to your class and added it. I got an error of 
Type 'CollectionEditor' is not defined.

I went to 'My Project' - 'References' and added a net reference to system design.  Error message was cleared.

I built the project and then component was available in the toolbox, which i added to the form and then built the project again, everything works fine.

I also changed the targeting compile to net 4 and it works fine also

Thanks again for nice component

----------


## Matchlighter

I have actually added somethings to it and have not updated it here. I will prepare it for release and upload it.  :Smilie:  Thanks for your Interest!

----------


## vixez

> Works fine for me and thanks for the nice progress bar
> 
> 
> I have vs 2010 net 4
> 
> I created a new windows form project, targeted at net 3.5.  I added to the project an 'existing item' browsed to your class and added it. I got an error of 
> Type 'CollectionEditor' is not defined.
> 
> I went to 'My Project' - 'References' and added a net reference to system design.  Error message was cleared.
> ...


That did the trick, thanks!




> I have actually added somethings to it and have not updated it here. I will prepare it for release and upload it.  Thanks for your Interest!


Nice  :Big Grin:

----------


## Matchlighter

Ok! I have got the new one ready! In this release I have add several features:
Text on top of progress. Use '%p' to display the value.Block Style with editable size and spacing.Editable Gradient Background.Editable Border Color.

There should be a screenshot attached now.

OK, that is all I can think of for the moment.  :Smilie:  It is Targeted at .NET 4.0 and is a VS2010 project. So I am not sure if it will open or be usable in older versions, but I have heard of a converter or something of the sort.

If you have any suggestions for the project, let me know!  :Smilie:

----------


## vixez

I just tried it out, working great  :Wink:

----------


## akhileshbc

Can you post a screen shot ?  :Smilie:

----------


## Matchlighter

> Can you post a screen shot ?


I just attached a Screenshot to post 12 that you can take a look at.

----------


## akhileshbc

> I just attached a Screenshot to post 12 that you can take a look at.


Super..  :Thumb: 

I liked the second one.
I didn't liked the third one. Maybe the color is giving me this feeling. I didn't run the project yet (but downloaded and keept it in my local CodeBank  :Smilie: )

----------


## Matchlighter

> Super.. 
> 
> I liked the second one.
> I didn't liked the third one. Maybe the color is giving me this feeling. I didn't run the project yet (but downloaded and keept it in my local CodeBank )


Mostly, the third one is showing off the block style feature. I tried to make the second one look like the Expression Studio 3 installer one. I apparently did a good job  :big yellow:

----------


## akhileshbc

> Mostly, the third one is showing off the block style feature. I tried to make the second one look like the Expression Studio 3 installer one. I apparently did a good job


Try giving some effects to the blocks. That might work  :Smilie:

----------


## proberts5

Hi. I've used this in a project built in Visual Studio 2013, and thought you might like to know that this code includes arithmetic that can cause an exception (arithmetic overflow which happens if MaxValue=MinValue), the exception is horrible at design time, affecting the project stability.  The exception happens because there ends up a division by zero.
I've added code that makes this progressbar do nothing if MaxValue=MinValue; as far as I can tell there are two point in the code where this needs to be caught. 
Perhaps there is a better solution. 
Overall, this a good product.

----------


## timfur

> Hi. I've used this in a project built in Visual Studio 2013, and thought you might like to know that this code includes arithmetic that can cause an exception (arithmetic overflow which happens if MaxValue=MinValue), the exception is horrible at design time, affecting the project stability.  The exception happens because there ends up a division by zero.
> I've added code that makes this progressbar do nothing if MaxValue=MinValue; as far as I can tell there are two point in the code where this needs to be caught. 
> Perhaps there is a better solution. 
> Overall, this a good product.


Sorry to resurrect an old thread...
I've got the bar installed and appears to be functioning correctly, I'm updating it with the code:



```
    
Private Sub ProgressBar(Total As Integer, Counter As Integer, Title As String, FileName As String)
        Dim Percent As Integer = (Counter / Total) * 100
        MsVistaProgressBar1.Visible = True
        MsVistaProgressBar1.Value = Percent
        If Title = "Checking: " Or Title = "Getting References: " Then
            MsVistaProgressBar1.DisplayText = Title & " " & FileName
        Else
            MsVistaProgressBar1.DisplayText = Title & " " & FileName & " " & Percent & "%"
        End If

    End Sub
```

But it doesn't seem to update during runtime. I've tried other controls which do update, but for some reason this doesn't
any advice?

----------


## proberts5

Make sure you first define the range for the Progressbar; for percent MsVistaProgressBar1.MinValue=0,MsVistaProgressBar1.MaxValue=100.
Then set MsVistaProgressBar1.value=<a value between MsVistaProgressBar1.MinValue and MsVistaProgressBar1.MaxValue> in your code somewhere.
You may wish to validate the Counter in your routine to make sure it's >=0 and <= Total.
Also that Total <>0 to avoid arithmetic overflow.

----------


## timfur

(you'll have to pardon my ignorance I'm completely self taught)

I double checked the values and everything is correct. But I did some changes that may give more info.

I originally wrote the program as a Windows Form Application, but because I wanted to integrate it into Inventor, I changed it to a Class Library and changed the start action to open the Inventor program. The first time the progress bar failed and I removed it until I could get the program functioning correctly. When I reinstated the progress bar that's when it wouldn't update,

So I changed the setup back to a Windows Form that started in my main user form and now the progress bar updates as expected.

Is there some setting somewhere that disables/enables 3rd party controls in a Class Library application?

----------


## proberts5

I'm not aware of anything that disables/enables 3rd party controls; and I'm not familiar with Inventor.
I have had issues with this progress bar in my Vbproject, though, to the point where I've had to resort to a backup.  That's how I know about  the gotchas regarding arithmetic overflow (causing an irreparable crash in the project at design time). 
first fix the progress bar code: -

 in the DrawBar routine modify the code: -

        If MaxValue = MinValue Then
            r.Width = CInt((Value * 1.0F / (2) * Me.Width))
        Else
            r.Width = CInt((Value * 1.0F / (MaxValue - MinValue) * Me.Width))
        End If

and in the DrawMarqueeBar routine: -

                If MaxValue <> MinValue Then
                    If CInt((Threshold.ThresholdPosition * 1.0F / (MaxValue - MinValue) * Me.Width)) > LastHiTH _
                    And MarqueeCenterPx >= CInt((Threshold.ThresholdPosition * 1.0F / (MaxValue - MinValue) * Me.Width)) _
                    And Threshold.ColorizeBar Then
                        LastHiTH = CInt((Threshold.ThresholdPosition * 1.0F / (MaxValue - MinValue) * Me.Width))
                        MarqeeColor = Threshold.ThresholdColor
                    End If
                Else
                    LastHiTH = Me.Width
                    MarqeeColor = Threshold.ThresholdColor
                End If

This fixes the points where it crashes when MaxValue=MinValue (i.e. when adjusting the design time parameters).

your routine should have an error trap and validation checks: -

Private Sub ProgressBar(Total As Integer, Counter As Integer, Title As String, FileName As String)
    Try

        if MsVistaProgressBar1.MinValue =  MsVistaProgressBar1.MaxValue Then Throw New Exception ("ProgressBar scale Error")

        if Total = 0 Then Throw New Exception ("Total cannot be zero")

        Dim Percent As Integer = (Counter / Total) * 100
        if Percent < MsVistaProgressBar1.MinValue Then Throw New Exception ("value under scale")
        if Percent >  MsVistaProgressBar1.MaxValue Then Throw New Exception("value over scale")

        MsVistaProgressBar1.Visible = True
        MsVistaProgressBar1.Value = Percent
        If Title = "Checking: " Or Title = "Getting References: " Then
            MsVistaProgressBar1.DisplayText = Title & " " & FileName
        Else
            MsVistaProgressBar1.DisplayText = Title & " " & FileName & " " & Percent & "%"
        End If

    Catch ex as exception
        MsgBox ex.Message
   End Try

    End Sub

----------


## timfur

Thanks for the error corrections in the code.
In regards to the code not updating, I'm guessing it has something to do with it being running too low in the program hierarchy. I may leave it in for any stand-alone programs, but when you create a class to be run within another program containing this progress-bar that's when the updating seems to be at best intermittent.

----------

