Hello
There is a vb6 source code on
http://www.allapi.net/php/redirect/redirect.php?action=download&id=370
I have convert the source code to vb.net, but the CPU real-time chart does
not work well.
I found the reason is that the properties of picturebox(picGraph) can not be
converted.
Picture1.ScaleMode = 0 - User
Picture1.ScaleHeight = 100
Picture1.ScaleWidth = 100
If ScaleMode set to "pixel", the result is same with vb.net.
The vb6 function
**************************************************************
Const SPACE = 5
Const BAR_WIDTH = 50
Public GraphPoints(0 To 99) As Long
Sub DrawUsage(lUsage As Long, picPercent As PictureBox, picGraph As
PictureBox)
Dim Cnt As Long
picPercent.ScaleMode = vbPixels
For Cnt = 0 To 10
picPercent.Line (SPACE, SPACE + Cnt * 3)-(SPACE + BAR_WIDTH, SPACE +
Cnt * 3 + 1), IIf(lUsage >= 100 - Cnt * 10 And lUsage <> 0, &HC000&,
&H4000&), BF
Next Cnt
ShiftPoints
GraphPoints(UBound(GraphPoints)) = lUsage
picGraph.Cls
For Cnt = LBound(GraphPoints) To UBound(GraphPoints) - 1
picGraph.Line (Cnt, 100 - GraphPoints(Cnt))-(Cnt + 1, 100 -
GraphPoints(Cnt + 1)), &H8000&
Next Cnt
End Sub
'Shift all the points from the graph one place to the left
Sub ShiftPoints()
Dim Cnt As Long
For Cnt = LBound(GraphPoints) To UBound(GraphPoints) - 1
GraphPoints(Cnt) = GraphPoints(Cnt + 1)
Next Cnt
End Sub
****************************************************************
I convert the code to vb.net
****************************************************************
Const SPACE As Short = 5
Const BAR_WIDTH As Short = 50
Private GraphPoints(99) As Integer
Sub DrawUsage(ByVal lUsage As Integer, ByVal picPercent As PictureBox,
ByVal picGraph As PictureBox)
Dim Cnt As Integer
For Cnt = 0 To 10
Dim p1 As New
Pen(System.Drawing.ColorTranslator.FromOle(&HC000&), 2)
Dim p2 As New
Pen(System.Drawing.ColorTranslator.FromOle(&H4000&), 2)
Dim x1 As New Point(SPACE, SPACE + Cnt * 3)
Dim x2 As New Point(SPACE + BAR_WIDTH, SPACE + Cnt * 3 + 1)
Dim e As Graphics = picPercent.CreateGraphics
If lUsage >= 100 - Cnt * 10 And lUsage <> 0 Then
e.DrawLine(p1, x1, x2)
Else
e.DrawLine(p2, x1, x2)
End If
Next Cnt
'Shift all the points from the graph one place to the left
For Cnt = LBound(GraphPoints) To UBound(GraphPoints) - 1
GraphPoints(Cnt) = GraphPoints(Cnt + 1)
Next Cnt
Dim e2 As Graphics = picGraph.CreateGraphics
e2.Clear(Color.Black)
GraphPoints(UBound(GraphPoints)) = lUsage
Dim p As New Pen(System.Drawing.ColorTranslator.FromOle(&HC000&), 1)
For Cnt = LBound(GraphPoints) To UBound(GraphPoints) - 1
Dim x3 As New Point(Cnt, 100 - GraphPoints(Cnt))
Dim x4 As New Point(Cnt + 1, 100 - GraphPoints(Cnt + 1))
e2.DrawLine(p, x3, x4)
Next Cnt
End Sub
*******************************************************************
Thank you