|
Hi,
thanks for this great control! I have 2 questions about it:
1) can I use it in a professional enviroment (of course with mentioning you in the code)?
2) How exactly do I get the Intellisense working, it doesn't seem to do anything....?
Wim (Belgium)
|
|
|
|
|
Yes, feel free to use SmoothProgressBar any way you like, if you want to give me a mention in the program that would be great!
As far as IntelliSense goes there is one condition I probably forgot to mention. Here's a quote from the GotDotNet message board from Tor-Erik:
Intellisense only works for assemblies you have a file reference to. Not for assemblies that you have project reference to or the current project. It proved to be too complicated to code around this shortcoming in VS.NET 2003, but this works with the XML comment feature in VS.NET 2005. So it will not work in the example project from the article here, but if you build this project and then create a new project with a file reference to SPB.dll it should work, provided you follow the instructions in the Help & XML download above.
|
|
|
|
|
This is a great progress bar that I'd really like to use on my next project, but I'm running into one frustrating bug. Some of the properties are not saving correctly when I close down the project and reopen it. I want the progress bar to run vertically with a gradient on foreground and background. This all works fine until I close the project and reopen.
When I reopen the project, the Orientation setting I'd previously had as 'Vertical' is horizontal again, and the BarColorStyle property reverts to Solid from Gradient. It seems all of the properties associated with the regular ProgressBar keep their correct values, but the properties specific to SmoothProgressBar don't stay set.
I also tried setting the default value of Orientation to Vertical, but it still comes up as Horizontal when I reopen a project. Any idea why this is ocurring, and what can I do to fix it?
Thanks in advance,
Mike
|
|
|
|
|
Hi Mike,
Wish I had noticed this earlier -
The reason this is happening is because the custom properties are not being "Serialized" - that is, saved to the project resource files for re-loading later.
It is easy to add this Save behavior to properties. For example, to save the Orientation property, do the following:
<Category("Behavior"), _
DefaultValue(GetType(Orient), "Horizontal"), _
Description("Orientation of the ProgressBar."), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property Orientation() As Orient
... etc
End Property
The key element is the Attribute "DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)". This tells the designer to serialize the visible value of the property, e.g. what you have selected in the box.
Be VERY VERY CAREFUL when you use these attributes. I would go read up on them somewhere before you start throwing a bunch of them on your Properties - you're as likely to destroy your project as you are to get it to save your Properties.
Muck up even one serialization setting and Visual Studio is likely to remove all references of a component from your project.
|
|
|
|
|
I've downloaded your progress bar, but when I go to add it to my toolbox, I get the message "Invalid parameter used." I used the dll file and had a form open in design when I did it. What am I doing wrong?
Dan
|
|
|
|
|
Well I've not tested with VS 2005 so if that's where the problem arises I don't know... I do know you must stop running (release or debug) before making any code or designer changes, I don't know if that also applies to adding controls to the toolbox as well, but it probably does. Other than that, I'm not sure what else to suggest.
|
|
|
|
|
Hi! I love this progress bar, but i tried to use it inside a panelEx(from Dotnetbar) and it was imposible . Any ideas?
For those who don`t know Dotnetbar, here is the url www.devcomponents.com
Thanks!
|
|
|
|
|
I'm not familiar with that control and I really don't want to d/l and install because of the 30 day trial limit.
My SmoothProgressBar does nothing special and should be able to be placed on any container control... remember to bring it to the front if it doesn't show up at first:
Panel1.Controls.Add(mySPB)
mySPB.BringToFront
This is referring to adding the control programatically...
|
|
|
|
|
I was setting the backcolor as transparent , that was the problem..Sorry and thanx!
|
|
|
|
|
Hi Stumpy842
Ive just stumbled upon your Progessbar and would like to try and use it in a small project of mine.
However, I’ve only been using VB.Net for a short time and would like to know how to use it in a project?
Is it a Add-in For VB.Net or is it stand alone program?
Do I need your permission to use it in my project (if I can get it to work;) )?
Do I need to install it into my project?
I really don’t know how to use you Progresbar but love to know how.
Thanks
Nick
|
|
|
|
|
Just download and build the source file from the article. Browse to the project directory and you will find a file named SPB.dll, this is the control.
You can add it to your toolbox in VS. With a form showing in the Designer you can right-click the Toolbox and select Add/Remove Items... now click the Browse button and navigate to the SPB.dll file. Select it, click Open button and then OK button.
Now you can use SmoothProgressBar in your project, just select it from the Toolbox and drop it on your form! :->
|
|
|
|
|
Thanks for that Stumpy842
I have one more question to ask if I may.
I have a form1 that has a blank tabcontrol on it, and a form2 which the user picks a number from a combobox which then creates the tabpages on form1. Each tabpage has a number of labels on them which read from an Excel file.
Can you show me an example of how i would write the code to make it work when my form1 loads the tabpages.
I’ve been asking around (on forums mainly) but I’m getting a little confused
Many Thanks
Nick
|
|
|
|
|
Actually that's kind of outside the scope of this article. I suggest going back to the forums, be specific about what you are doing and try to post some code sample of what you've tried so far...
|
|
|
|
|
Hi, I found this code really useful. I've extended it to allow for divisions along the bar itself. The code can be found here:
SmoothProgressBar.vb
Screenshot here:
Screenshot
Cheers!
|
|
|
|
|
Wow, that's really nice! That's what I love about the extensibility of the .NET stuff, you can make it do just about whatever you want with a little tweaking. Thanks for your addition!
|
|
|
|
|
None of the above links works.
Time out, time out, time out...
... and page not found!!
It would be a great thing, when you move something,
to update all the referring links.
Thanks you.
Luca Crisi
|
|
|
|
|
Now, this is what the progress bar should have been from the beginning! Thank you Stumpy842 for posting it!
Note to those looking to take advantage of this control: Ensure that you get dbembibre's addition (also in comments) to display the current percentage. Also, make use of the demo application. It's a convenient way to come up with appropriate values for your particular needs.
|
|
|
|
|
Thank you for your comments! If anyone wants to use this control for their projects I suggest reading through all the comments posted here to get a better idea how the control can be extended, and to get more code examples. I especially like dbembibre's addition of the progress percent.
|
|
|
|
|
First of all: Great Progressbar, just nice to use.
In Addition to the suggestions made by "dbembibre", i would like to suggest my
way of adding Textdisplay to the progressbar.
My goals:
1.Texthighlighting inside the PB
2.Looking after Vertical and Reverse Display of PB
3.Additional Text (eg."(... of ... bytes)")
4.Properties that fit into your code.
Here it is (and please don´t forget to post some opinions on this one):
'//Private Variables<br />
Private mborderstyle As BorderStyle = BorderStyle.Fixed3D<br />
Private m_ProgressTextEnable As Boolean = True<br />
Private m_ProgressTextFont As System.Drawing.Font = New Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold)<br />
Private m_ProgressTextColor As System.Drawing.Color = SystemColors.ControlText<br />
Private m_ProgressTextColorHighlight As System.Drawing.Color = SystemColors.HighlightText<br />
Private m_ProgressTextAdd As String<br />
<br />
'OnPaint Event<br />
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)<br />
Dim percent As Decimal = CDec(val - min) / CDec(max - min)<br />
Dim rectf As RectangleF = RectangleF.op_Implicit(Me.ClientRectangle)<br />
Dim brush<br />
<br />
Dim TextSize As SizeF<br />
Dim ProgressText As String<br />
<br />
' Draw the background of the ProgressBar control.<br />
If mbackcolorstyle = ColorStyle.Gradient Then<br />
<br />
brush = New LinearGradientBrush(rectf, _<br />
mbackcolor1, mbackcolor2, mbackgradientmode)<br />
<br />
If mbacksigmamode = SigmaMode.SigmaBell Then _<br />
brush.SetSigmaBellShape(mbacksigmafocus, mbacksigmascale)<br />
<br />
e.Graphics.FillRectangle(brush, rectf)<br />
<br />
End If<br />
<br />
' Calculate area for drawing the progress.<br />
If isHorz Then<br />
rectf.Width = rectf.Width * percent<br />
If isRevs Then rectf.X = mwidth - rectf.Width<br />
Else<br />
rectf.Height = rectf.Height * percent<br />
If Not isRevs Then rectf.Y = mheight - rectf.Height<br />
End If<br />
<br />
' Draw the progress meter.<br />
If rectf.Width > 0 AndAlso rectf.Height > 0 Then<br />
<br />
If mbarcolorstyle = ColorStyle.Solid Then<br />
brush = New SolidBrush(mbarcolor1)<br />
Else<br />
If mbargradientstretch = StretchMode.Normal Then<br />
brush = New LinearGradientBrush(Me.ClientRectangle, _<br />
mbarcolor1, mbarcolor2, mbargradientmode)<br />
Else<br />
brush = New LinearGradientBrush(rectf, _<br />
mbarcolor1, mbarcolor2, mbargradientmode)<br />
End If<br />
If mbarsigmamode = SigmaMode.SigmaBell Then _<br />
brush.SetSigmaBellShape(mbarsigmafocus, mbarsigmascale)<br />
End If<br />
<br />
e.Graphics.FillRectangle(brush, rectf)<br />
<br />
End If<br />
<br />
''/////////////BEGIN Painting the Progresstext///////////////<br />
If rectf.Width > 0 And Me.m_ProgressTextEnable = True Then<br />
ProgressText = Format((Value - min) / (max - min), "0%")<br />
<br />
Dim clipRect As Rectangle = Rectangle.Empty<br />
Dim pos As PointF = PointF.Empty<br />
Dim topGap As Integer = 0<br />
Dim g As Graphics = e.Graphics<br />
Dim sformat As New StringFormat<br />
<br />
TextSize = e.Graphics.MeasureString(ProgressText, Me.m_ProgressTextFont)<br />
<br />
If Me.BorderStyle = BorderStyle.Fixed3D Then<br />
topGap = 1<br />
End If<br />
<br />
'
If isHorz Then<br />
pos = New PointF((WorkRect.Width - TextSize.Width) / 2, (WorkRect.Height - TextSize.Height) / 2 + topGap)<br />
Else<br />
pos = New PointF((WorkRect.Width - TextSize.Height) / 2, (WorkRect.Height - TextSize.Width) / 2)<br />
End If<br />
<br />
g.Clip = New Region(rectf)<br />
<br />
If isHorz Then<br />
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColorHighlight), pos)<br />
Else<br />
sformat.FormatFlags = StringFormatFlags.DirectionVertical<br />
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColorHighlight), pos, sformat)<br />
End If<br />
<br />
'//Now draw the rest of the text<br />
If isHorz Then<br />
If isRevs Then<br />
clipRect = New Rectangle(Me.ClientRectangle.Left, rectf.Top, Me.ClientRectangle.Width - rectf.Width, rectf.Height)<br />
Else<br />
clipRect = New Rectangle(rectf.Left + rectf.Width, rectf.Top, Me.ClientRectangle.Width - rectf.Width, rectf.Height)<br />
End If<br />
Else<br />
If isRevs Then<br />
clipRect = New Rectangle(rectf.Left, Me.ClientRectangle.Top + rectf.Height, rectf.Width, Me.ClientRectangle.Height - rectf.Height)<br />
Else<br />
clipRect = New Rectangle(rectf.Left, Me.ClientRectangle.Top, rectf.Width, Me.ClientRectangle.Height - rectf.Height)<br />
End If<br />
End If<br />
<br />
g.Clip = New Region(clipRect)<br />
<br />
If isHorz Then<br />
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColor), pos)<br />
Else<br />
sformat.FormatFlags = StringFormatFlags.DirectionVertical<br />
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColor), pos, sformat)<br />
End If<br />
End If<br />
<br />
''/////////////END Painting the Progresstext///////////////<br />
<br />
<br />
If Not brush Is Nothing Then brush.Dispose()<br />
<br />
' Draw a border around the ProgressBar control.<br />
If Me.BorderStyle <> BorderStyle.None Then DrawBorder(e.Graphics)<br />
End Sub<br />
<br />
'Properties<br />
<Category("Appearance"), DefaultValue(GetType(Boolean), "True"), _<br />
Description("Enable / Disable displaying the percentage text inside the progress bar")> _<br />
Public Property ProgressTextEnable() As Boolean<br />
Get<br />
Return m_ProgressTextEnable<br />
End Get<br />
Set(ByVal Value As Boolean)<br />
m_ProgressTextEnable = Value<br />
Me.Invalidate()<br />
End Set<br />
End Property<br />
<br />
<Category("Appearance"), DefaultValue(GetType(Font), "Tahoma; 8,25pt"), _<br />
Description("Determines the font for displaying the percentage text inside the progress bar")> _<br />
Public Property ProgressTextFont() As Font<br />
Get<br />
Return m_ProgressTextFont<br />
End Get<br />
Set(ByVal Value As Font)<br />
m_ProgressTextFont = Value<br />
Me.Invalidate()<br />
End Set<br />
End Property<br />
<br />
<Category("Appearance"), DefaultValue(GetType(Color), "ControlText"), _<br />
Description("Determines the color of text displayed inside the progressbar.")> _<br />
Public Property ProgressTextColor() As Color<br />
Get<br />
Return m_ProgressTextColor<br />
End Get<br />
Set(ByVal Value As Color)<br />
m_ProgressTextColor = Value<br />
Me.Invalidate()<br />
End Set<br />
End Property<br />
<br />
<Category("Appearance"), DefaultValue(GetType(Color), "HighlightText"), _<br />
Description("Determines the inverted color of text displayed inside the progressbar.")> _<br />
Public Property ProgressTextColorHighlight() As Color<br />
Get<br />
Return m_ProgressTextColorHighlight<br />
End Get<br />
Set(ByVal Value As Color)<br />
m_ProgressTextColorHighlight = Value<br />
Me.Invalidate()<br />
End Set<br />
End Property<br />
<br />
<Category("Appearance"), DefaultValue(""), _<br />
Description("Optional text to add to the progressbar percentage text.")> _<br />
Public Property ProgressTextAdd() As String<br />
Get<br />
Return m_ProgressTextAdd<br />
End Get<br />
Set(ByVal Value As String)<br />
m_ProgressTextAdd = Value<br />
Me.Invalidate()<br />
End Set<br />
End Property
|
|
|
|
|
Forgot to add the ProgressTextAdd. Replace the following lines:
''If rectf.Width > 0 And Me.m_ProgressTextEnable = True Then<br />
ProgressText = Format((Value - min) / (max - min), "0%")<br />
<br />
If m_ProgressTextAdd <> "" Then ProgressText = ProgressText & " " & m_ProgressTextAdd
Sorry about that. :->
|
|
|
|
|
I like what you've done! However, the calculations for the clipRect need adjusted to avoid painting all the way to the edges of the control, i.e. over top of the border.
Try this code for the OnPaint handler:
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim percent As Decimal = CDec(val - min) / CDec(max - min)
Dim rectf As RectangleF = RectangleF.op_Implicit(Me.ClientRectangle)
Dim brush
If mbackcolorstyle = ColorStyle.Gradient Then
brush = New LinearGradientBrush(rectf, _
mbackcolor1, mbackcolor2, mbackgradientmode)
If mbacksigmamode = SigmaMode.SigmaBell Then _
brush.SetSigmaBellShape(mbacksigmafocus, mbacksigmascale)
e.Graphics.FillRectangle(brush, rectf)
End If
If isHorz Then
rectf.Width = rectf.Width * percent
If isRevs Then rectf.X = mwidth - rectf.Width
Else
rectf.Height = rectf.Height * percent
If Not isRevs Then rectf.Y = mheight - rectf.Height
End If
If rectf.Width > 0 AndAlso rectf.Height > 0 Then
If mbarcolorstyle = ColorStyle.Solid Then
brush = New SolidBrush(mbarcolor1)
Else
If mbargradientstretch = StretchMode.Normal Then
brush = New LinearGradientBrush(Me.ClientRectangle, _
mbarcolor1, mbarcolor2, mbargradientmode)
Else
brush = New LinearGradientBrush(rectf, _
mbarcolor1, mbarcolor2, mbargradientmode)
End If
If mbarsigmamode = SigmaMode.SigmaBell Then _
brush.SetSigmaBellShape(mbarsigmafocus, mbarsigmascale)
End If
e.Graphics.FillRectangle(brush, rectf)
End If
If Not brush Is Nothing Then brush.Dispose()
If Me.BorderStyle <> BorderStyle.None Then DrawBorder(e.Graphics)
If Me.m_ProgressTextEnable Then
Dim TextSize As SizeF
Dim ProgressText As String
Dim rect, clipRect As Rectangle
Dim pos As PointF
Dim topGap As Integer
Dim g As Graphics = e.Graphics
Dim sformat As New StringFormat
ProgressText = Format((Value - min) / (max - min), "0%")
If m_ProgressTextAdd <> "" Then ProgressText &= " " & m_ProgressTextAdd
TextSize = e.Graphics.MeasureString(ProgressText, Me.m_ProgressTextFont)
rect = [Rectangle].Round(rectf)
If Me.BorderStyle = BorderStyle.None Then
topGap = 1
clipRect = Me.ClientRectangle
Else
topGap = 2
clipRect = [Rectangle].Inflate(Me.ClientRectangle, -1, -1)
End If
g.Clip = New Region([Rectangle].Intersect(rect, clipRect))
With clipRect
If isHorz Then
pos = New PointF((.Width - TextSize.Width) / 2, (.Height - TextSize.Height) / 2 + topGap)
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColorHighlight), pos)
Else
pos = New PointF((.Width - TextSize.Height) / 2, (.Height - TextSize.Width) / 2)
sformat.FormatFlags = StringFormatFlags.DirectionVertical
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColorHighlight), pos, sformat)
End If
End With
Dim r As New Region(clipRect)
r.Exclude(rect)
g.Clip = r
If isHorz Then
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColor), pos)
Else
sformat.FormatFlags = StringFormatFlags.DirectionVertical
g.DrawString(ProgressText, Me.m_ProgressTextFont, New SolidBrush(Me.m_ProgressTextColor), pos, sformat)
End If
r.Dispose() : sformat.Dispose()
End If
End Sub
|
|
|
|
|
The smooth progressbar is nicely executed. The demo is actually amongst the best demos on this site to show the functionality of the control. Congrats! I look forward to your other contributions.
neuralsea
|
|
|
|
|
Thanks for the compliments! I'm glad you like my article.
|
|
|
|
|
I add code to show a percent in the progress bar.
Excuse my broken english, but im Spanish.
<br />
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)<br />
<br />
Dim percent As Decimal = CDec(val - min) / CDec(max - min)<br />
Dim rectf As RectangleF = RectangleF.op_Implicit(Me.ClientRectangle)<br />
Dim brush<br />
<br />
Dim TextSize As SizeF<br />
Dim TheCaption As String<br />
Dim RangeDiff As Double<br />
Dim sngDevide As Single<br />
Dim sngX As Single<br />
Dim sngY As Single<br />
Dim TextFont As Font = New Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold)<br />
<br />
' Draw the background of the ProgressBar control.<br />
If mbackcolorstyle = ColorStyle.Gradient Then<br />
<br />
brush = New LinearGradientBrush(rectf, _<br />
mbackcolor1, mbackcolor2, mbackgradientmode)<br />
<br />
If mbacksigmamode = SigmaMode.SigmaBell Then _<br />
brush.SetSigmaBellShape(mbacksigmafocus, mbacksigmascale)<br />
<br />
e.Graphics.FillRectangle(brush, rectf)<br />
<br />
End If<br />
<br />
' Calculate area for drawing the progress.<br />
If isHorz Then<br />
rectf.Width = rectf.Width * percent<br />
If isRevs Then rectf.X = mwidth - rectf.Width<br />
Else<br />
rectf.Height = rectf.Height * percent<br />
If Not isRevs Then rectf.Y = mheight - rectf.Height<br />
End If<br />
<br />
' Draw the progress meter.<br />
If rectf.Width > 0 AndAlso rectf.Height > 0 Then<br />
<br />
If mbarcolorstyle = ColorStyle.Solid Then<br />
brush = New SolidBrush(mbarcolor1)<br />
Else<br />
If mbargradientstretch = StretchMode.Normal Then<br />
brush = New LinearGradientBrush(Me.ClientRectangle, _<br />
mbarcolor1, mbarcolor2, mbargradientmode)<br />
Else<br />
brush = New LinearGradientBrush(rectf, _<br />
mbarcolor1, mbarcolor2, mbargradientmode)<br />
End If<br />
If mbarsigmamode = SigmaMode.SigmaBell Then _<br />
brush.SetSigmaBellShape(mbarsigmafocus, mbarsigmascale)<br />
End If<br />
<br />
e.Graphics.FillRectangle(brush, rectf)<br />
<br />
End If<br />
<br />
'<br />
If rectf.Width > 0 Then<br />
' Calcular el porcentaje del progress bar<br />
RangeDiff = max - min<br />
TheCaption = Format((Value - min) / RangeDiff, "0%")<br />
<br />
' Obtener las dimensiones que necesitamos<br />
sngDevide = CSng(((Value - min) / RangeDiff) * rectf.Width)<br />
<br />
' Obtener el alto y largo del string<br />
TextSize = e.Graphics.MeasureString(TheCaption, TextFont)<br />
<br />
' Ajustar el texto al centro<br />
sngX = CType((Me.Width / 2 - TextSize.Width / 2), Single)<br />
<br />
'sngX = 1 'Sería ajuastado a la izquierda<br />
'sngX = (TheControl.Width - TextSize.Width) - 1 'Sería ajustado a la derecha<br />
<br />
sngY = (Me.Height - TextSize.Height) / 2<br />
<br />
' Dibujar el texto en el progressbar<br />
e.Graphics.DrawString(TheCaption, TextFont, New SolidBrush(Color.Orange), sngX, sngY)<br />
End If<br />
<br />
'<br />
If Not brush Is Nothing Then brush.Dispose()<br />
<br />
' Draw a border around the ProgressBar control.<br />
If Me.BorderStyle <> BorderStyle.None Then DrawBorder(e.Graphics)<br />
<br />
End Sub<br />
|
|
|
|
|
Thanks for posting your code, it works very nicely!
|
|
|
|
|