Morten,
The way I call this method is like:
Me.FormatDollarsLabelForNegative(lblExpenseChgValue)
This method is called whenever the application first opens AND whenever a
new calculation (elsewhere in the app) is performed that would change
these
values.
What I see happening is that after the line of code above, if I look at
the
'lblExpenseChgValue.Text' value in the command window, I will see:
($508,305). This is the correct format. However, the color of the font
seems
to come out correctly but the '-' sign appears adjacent to the number
instead of the '( )'.
So, in the code below if I change Red to Green, the color of the font
will
be green. It seems that the change to the 'text' property is the problem,
not the color of the font.
The bizarre thing is, that once this window is open, if I perform a
recalculation which results in these formatting functions to be called
again, the value that appears is now correct both in format and in color.
So, it appears it is just the initial loading of the screen that is the
problem.
Private Sub FormatDollarsLabelForNegative(ByRef lbl As
System.Windows.Forms.Label)
'the label value will already be string, we need to convert it
from
string
'back to decimal
Dim _ldValue As Decimal
Dim _lsReplace As String
'this method removes an current parenthesis that might already be in
place
_lsReplace = RemoveParenthesis(lbl.Text)
_lsReplace = _lsReplace.Replace("$", "")
_lsReplace = _lsReplace.Replace(",", "")
_ldValue = CDec(_lsReplace)
If _ldValue < CDec(0.0) Then
'need to remove the minus value
lbl.Text = "(" & lbl.Text.Replace("-", "") & ")"
lbl.Font = New System.Drawing.Font("Microsoft Sans Serif",
8.25!, FontStyle.Bold)
lbl.ForeColor = System.Drawing.Color.Red
Else
lbl.Font = New System.Drawing.Font("Microsoft Sans Serif",
8.25!, FontStyle.Bold)
lbl.ForeColor = System.Drawing.Color.Black
End If
End Sub