可以测试驱动器(包含优盘自动识别插入、卸载)的读(Read)写(Write)速度,并以图形化的方式直观显示
读写按照二进制形式进行测试
程序运行效果图如下:
主要源码如下:
1、柱状图控件源码
Public
Class SpeedView
Class SpeedView
Private xStep, yStep As Single
Private mMaxSpeed As Integer = 10
Private Infos As New ArrayList
Public Class InfoClass Info
Public Write As Integer
Public Read As Integer
Public y As Single
Public DrawWrite As Boolean
Public DrawRead As Boolean
End Class
Public Property MaxSpeed()Property MaxSpeed() As Integer
Get
Return mMaxSpeed
End Get
Set(ByVal value As Integer)
If mMaxSpeed <> value Then
mMaxSpeed = value
PictureBox1.Invalidate()
Me.Invalidate()
End If
End Set
End Property
Private Sub PictureBox1_Paint()Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim point1, point2 As PointF
'绘制网格
For i As Integer = 1 To 9
point1 = New PointF(xStep * i, 0)
point2 = New PointF(xStep * i, PictureBox1.Height)
e.Graphics.DrawLine(Pens.Blue, point1, point2)
Next
'绘制图形
For i As Integer = 0 To Infos.Count - 1
Dim ThisInfo As Info = CType(Infos(i), Info)
'绘制写速度
If ThisInfo.DrawWrite Then
Dim p1, p2 As Point
p1 = New Point(0, yStep * i)
p2 = New Point(ThisInfo.Write * PictureBox1.Width / (MaxSpeed * 1024), yStep * i)
e.Graphics.DrawLine(New Pen(Color.Red, 4), p1, p2)
End If
'绘制读速度
If ThisInfo.DrawRead Then
Dim p1, p2 As Point
p1 = New Point(0, yStep * i + 4)
p2 = New Point(ThisInfo.Read * PictureBox1.Width / (MaxSpeed * 1024), yStep * i + 4)
e.Graphics.DrawLine(New Pen(Color.Black, 4), p1, p2)
End If
Next
End Sub
Private Sub PictureBox1_SizeChanged()Sub PictureBox1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.SizeChanged
xStep = PictureBox1.Width / 10
yStep = PictureBox1.Height / 12
End Sub
Private Sub SpeedView_Paint()Sub SpeedView_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'绘制x轴刻度
For i As Integer = 0 To 10
Dim point As Point
Dim str As String = (MaxSpeed * i / 10).ToString
Dim size As SizeF = e.Graphics.MeasureString(str, Me.Font)
point = New Point(PictureBox1.Left + i * xStep - size.Width / 2, PictureBox1.Bottom)
e.Graphics.DrawString(str, Me.Font, Brushes.Black, point)
Private xStep, yStep As Single
Private mMaxSpeed As Integer = 10
Private Infos As New ArrayList
Public Class InfoClass Info
Public Write As Integer
Public Read As Integer
Public y As Single
Public DrawWrite As Boolean
Public DrawRead As Boolean
End Class
Public Property MaxSpeed()Property MaxSpeed() As Integer
Get
Return mMaxSpeed
End Get
Set(ByVal value As Integer)
If mMaxSpeed <> value Then
mMaxSpeed = value
PictureBox1.Invalidate()
Me.Invalidate()
End If
End Set
End Property
Private Sub PictureBox1_Paint()Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim point1, point2 As PointF
'绘制网格
For i As Integer = 1 To 9
point1 = New PointF(xStep * i, 0)
point2 = New PointF(xStep * i, PictureBox1.Height)
e.Graphics.DrawLine(Pens.Blue, point1, point2)
Next
'绘制图形
For i As Integer = 0 To Infos.Count - 1
Dim ThisInfo As Info = CType(Infos(i), Info)
'绘制写速度
If ThisInfo.DrawWrite Then
Dim p1, p2 As Point
p1 = New Point(0, yStep * i)
p2 = New Point(ThisInfo.Write * PictureBox1.Width / (MaxSpeed * 1024), yStep * i)
e.Graphics.DrawLine(New Pen(Color.Red, 4), p1, p2)
End If
'绘制读速度
If ThisInfo.DrawRead Then
Dim p1, p2 As Point
p1 = New Point(0, yStep * i + 4)
p2 = New Point(ThisInfo.Read * PictureBox1.Width / (MaxSpeed * 1024), yStep * i + 4)
e.Graphics.DrawLine(New Pen(Color.Black, 4), p1, p2)
End If
Next
End Sub
Private Sub PictureBox1_SizeChanged()Sub PictureBox1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.SizeChanged
xStep = PictureBox1.Width / 10
yStep = PictureBox1.Height / 12
End Sub
Private Sub SpeedView_Paint()Sub SpeedView_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'绘制x轴刻度
For i As Integer = 0 To 10
Dim point As Point
Dim str As String = (MaxSpeed * i / 10).ToString
Dim size As SizeF = e.Graphics.MeasureString(str, Me.Font)
point = New Point(PictureBox1.Left + i * xStep - size.Width / 2, PictureBox1.Bottom)
e.Graphics.DrawString(str, Me.Font, Brushes.Black, point)