JayWeb
Member
- Joined
- May 27, 2010
- Messages
- 7
- Programming Experience
- 1-3
Hi,
I have added a progress bar user control which I downloaded to my project.
The code follows:
The problem is, when I change the progress bar in any way on the designer, the designer code changes to:
Me.pbNetworkUp = New ConsoleX.UC_PBar()
which causes an error and I need to change it to:
Me.pbNetworkUp = New UC_PBar()
Its starting to get quite annoying, can someone tell me how to fix it. Thanks.
I have added a progress bar user control which I downloaded to my project.
The code follows:
VB.NET:
Public Class UC_PBar
' Define a variable to store the current percentage of the bar, to save use recalculating
Private mPercentage As Single = 0.0
' Define a variable to store the Range, ABS(Min) + ABS(Max)
Private mRange As Long = 100
#Region "Properties"
#Region "Value Properties"
Private mMaximum As Long = 100
< _
System.ComponentModel.Category("Bar Settings") _
, System.ComponentModel.DisplayName("Maximum") _
, System.ComponentModel.Description("Maximum Value that the bar value can be.") _
> Public Property Maximum() As Long
Get
Return mMaximum
End Get
Set(ByVal value As Long)
If value = mMinimum Then
Throw New Exception("Maximums's value can not equal minimum.")
Exit Property
End If
If value = mMinimum Then
Throw New Exception("Maximums's value can be less than minimum.")
Exit Property
End If
If value < mValue Then
Throw New Exception("Maximums's value can not be less than value.")
Exit Property
End If
mMaximum = value
UpdateValues()
Me.Refresh()
End Set
End Property
Private mMinimum As Long = 0
< _
System.ComponentModel.Category("Bar Settings") _
, System.ComponentModel.DisplayName("Minimum") _
, System.ComponentModel.Description("Minimum Value that the bar value can be.") _
> Public Property Minimum() As Long
Get
Return mMinimum
End Get
Set(ByVal value As Long)
If value > mMaximum Then
Throw New Exception("Minimum can not exceed maximum.")
Exit Property
End If
If value = mMaximum Then
Throw New Exception("Minimum's value can not equal maximum.")
Exit Property
End If
If value > mValue Then
Throw New Exception("Minimum's value can not exceed value.")
Exit Property
End If
mMinimum = value
UpdateValues()
Me.Refresh()
End Set
End Property
Private mValue As Long = 0
< System.ComponentModel.Category("Bar Settings"), System.ComponentModel.DisplayName("Value") , System.ComponentModel.Description("Current value of the bar.") > Public Property Value() As Long
Get
Return mValue
End Get
Set(ByVal value As Long)
If value < mMinimum Then
Throw New Exception("Value is less than minimum.")
Exit Property
End If
If value > mMaximum Then
Throw New Exception("Value exceeds maximum allowed.")
Exit Property
End If
mValue = value
UpdateValues()
Me.Refresh()
End Set
End Property
#End Region
#Region "Color Properties"
Private mBGColor As Color
< _
System.ComponentModel.Category("Bar Settings") _
, System.ComponentModel.DisplayName("Background Color") _
, System.ComponentModel.Description("Color used as the background to the bar") _
> Public Property BGColor() As Color
Get
Return mBGColor
End Get
Set(ByVal value As Color)
mBGColor = value
Me.Refresh()
End Set
End Property
Private mBorderColor As Drawing.Color
< _
System.ComponentModel.Category("Bar Settings") _
, System.ComponentModel.DisplayName("Border Color") _
, System.ComponentModel.Description("Color ofthe border.") _
> Public Property BorderColor() As Drawing.Color
Get
Return mBorderColor
End Get
Set(ByVal value As Drawing.Color)
mBorderColor = value
Me.Refresh()
End Set
End Property
Private mBarColor As Drawing.Color
< _
System.ComponentModel.Category("Bar Settings") _
, System.ComponentModel.DisplayName("Bar Color") _
, System.ComponentModel.Description("Color of the percentage portion of the bar.") _
> Public Property BarColor() As Drawing.Color
Get
Return mBarColor
End Get
Set(ByVal value As Drawing.Color)
mBarColor = value
Me.Refresh()
End Set
End Property
#End Region
#End Region
Private Sub UpdateValues()
' Caluculate the value for range
mRange = Math.Abs(mMinimum - mMaximum) 'Minor error in calculating range. doh!
' Define where the zero point is.
Dim ZeroPoint As Long
ZeroPoint = Math.Abs(mMinimum)
' Work out where value lays in the range
Dim tValue As Long
tValue = ZeroPoint + mValue
' Caluculate this as percentage of the range.
mPercentage = tValue / mRange
End Sub
Private Sub UControl_PBar_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
DrawPBar(e.Graphics)
End Sub
Private Sub DrawPBar(ByRef g As Graphics)
' Get out pens
Dim mBGPen As New Pen(mBGColor, 1)
Dim mBordPen As New Pen(mBorderColor, 2)
Dim mBarPen As New Pen(mBarColor, 1)
' Draw Bar using pens
g.FillRectangle(mBGPen.Brush, 0, 0, Me.Width, Me.Height)
g.FillRectangle(mBarPen.Brush, 0, 0, CSng(Me.Width * mPercentage), Me.Height)
g.DrawRectangle(mBordPen, 0, 0, Me.Width, Me.Height)
' Tidy up Pens
mBarPen.Dispose()
mBordPen.Dispose()
mBGPen.Dispose()
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set the Default color values
mBGColor = Drawing.SystemColors.Control
mBorderColor = Color.Black
mBarColor = Color.Red
End Sub
End Class
The problem is, when I change the progress bar in any way on the designer, the designer code changes to:
Me.pbNetworkUp = New ConsoleX.UC_PBar()
which causes an error and I need to change it to:
Me.pbNetworkUp = New UC_PBar()
Its starting to get quite annoying, can someone tell me how to fix it. Thanks.