紫外工控论坛

 找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 2227|回复: 0

[VB/VB.NET] 一个不错的类似进程管理器的VB画图程序

[复制链接]
水瓶座的小强 发表于 2011-6-6 15:10:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
file:///C:/Documents%20and%20Settings/lq/Application%20Data/Tencent/Users/479623060/QQ/WinTemp/RichOle/_F}OVY}D$TLWO30ODZLTXQE.jpg
这个程序点击左边和右边的按钮可以使曲线绘制出来 ,然后整个图形从右至左刷新,可以用来做实时曲线图使用,只需要修改部分代码,是个不错的学习资料,我也是从网上扒下来的,特此分享,并特别感谢写这段代码的同志!
Form 窗口下的程序

''''''''''''''''''''''''''''''''''''
'Simple diagrams
'Just add new reference to cls_diagram!
'By Sami Riihilahti
'Free to use at any case!
''''''''''''''''''''''''''''''''''''
Public linediagram As New Cls_diagram
Public tancounter As Single 'We are using this just to create tan diagrams
Private Sub Command1_Click()
tancounter = tancounter + 1
End Sub
Private Sub Command2_Click()
tancounter = tancounter - 1
End Sub
Private Sub Form_Load()
With linediagram
        .InitDiagram Picture_line, RGB(255, 255, 0), True, , True
        .Max = 100
        .HorzSplits = 9
        .VertSplits = 9
        .DiagramType = TYPE_LINE
        .RePaint
    End With
End Sub
Private Sub Picture_line_Paint()
    linediagram.RePaint
End Sub
Private Sub Timer1_Timer()
    'Just randomize a new value in this sample
    Dim value As Single
    value = tancounter
    linediagram.AddValue value
    linediagram.RePaint
    Text1.Text = tancounter
End Sub
类模块中的程序
Public HorzSplits As Long
Public VertSplits As Long
Public Max As Single 'Max value
Private ValueArray() As Single 'Array to hold values
Private mem_LineColor As Long
Private mem_GridColor As Long
Private mem_ShowGrid As Boolean
Private mem_pBox As PictureBox
Private mem_pBoxHeight As Long
Private mem_pBoxWidth As Long
Private mem_movingGrid As Boolean
Private StartPosition As Long 'Needed to not to display first zero values when starting a new diagram
Private GridPosition As Long
Private Liqiang As Integer
Private Pengcen As Long
Public Enum ENUM_DIAGRAMTYPE
    TYPE_LINE = 0
    TYPE_POINT = 1
End Enum
Public DiagramType As ENUM_DIAGRAMTYPE 'Type of diagram (line or point)
Const const_tolerance = 0.0001 'Used to fix last line tolerance problem in some cases
Public Function InitDiagram(pBox As PictureBox, LineColor As Long, ShowGrid As Boolean, Optional GridColor As Variant, Optional MovingGrid As Variant)
   
    pBox.ScaleMode = vbPixels 'Set pixel scale mode
   
    mem_LineColor = LineColor
    mem_ShowGrid = ShowGrid
   
    pBox.ScaleHeight = 400
    pBox.ScaleWidth = 600
    mem_pBoxHeight = pBox.ScaleHeight
    mem_pBoxWidth = pBox.ScaleWidth
   
    'If user didn't give a grid color, we are using default (dark green) color
    If IsMissing(GridColor) Then
        mem_GridColor = RGB(0, 130, 0) 'Dark green
    Else:
        mem_GridColor = GridColor
    End If
   
    'If user didn't give a movingGrid parameter, we are using default (off)
    If IsMissing(MovingGrid) Then
        mem_movingGrid = False
    Else:
        mem_movingGrid = MovingGrid
    End If
   
    Set mem_pBox = pBox 'Save picturebox, so we dont need to ask it again
   
    'Allocate array to hold all diagram values (value per pixel)
    Liqiang = mem_pBoxWidth / 120
    ReDim ValueArray(119)
    StartPosition = Liqiang * 120 - 5
    Pengcen = Liqiang * 120
   
    GridPosition = Liqiang
   
End Function
Public Sub AddValue(value As Single)
   
    Dim l As Long
   
   
    'Check if InitDiagram has not been executed yet
    If mem_pBox Is Nothing Then
        'Failed! (exit function)
        Exit Sub
    End If
   
    'Move all values from array one position lower
    For l = 1 To 119
        ValueArray(l - 1) = ValueArray(l)
    Next
   
    'Max can't be 0 or smaller
    If Max <= 0 Then Max = 1
   
    'Add new value to the last element of array
    ValueArray(l - 1) = mem_pBoxHeight - ((value / Max) * mem_pBoxHeight)
    If StartPosition >= 10 Then StartPosition = StartPosition - Liqiang
   
    GridPosition = GridPosition - Liqiang
End Sub
Public Sub RePaint()
    Dim x As Single
    Dim y As Single
    Dim l As Long
    Dim i As Integer
   
    'Check if InitDiagram has not been executed yet
    If mem_pBox Is Nothing Then
        'Failed! (exit sub)
        Exit Sub
    End If
    'Create background image
    'First clear hole picture box, then draw grid if set, then draw diagram
   
    mem_pBox.Cls 'Clear picturebox
   
    'Draw grid if set
    If (mem_ShowGrid) Then
        mem_pBox.ForeColor = mem_GridColor
        
        'Draw vertical lines with or without using gridposition
        If (mem_movingGrid) Then
            For x = GridPosition To mem_pBoxWidth - 1 Step ((mem_pBoxWidth - 1) / (VertSplits + 1)) - const_tolerance
                mem_pBox.Line (x, 0)-(x, mem_pBoxHeight)
            Next
        Else:
            For x = 0 To mem_pBoxWidth - 1 Step ((mem_pBoxWidth - 1) / (VertSplits + 1)) - const_tolerance
                mem_pBox.Line (x, 0)-(x, mem_pBoxHeight)
            Next
        End If
        
        For y = 0 To mem_pBoxHeight - 1 Step ((mem_pBoxHeight - 1) / (HorzSplits + 1)) - const_tolerance
            mem_pBox.Line (0, y)-(mem_pBoxWidth, y)
        Next
        'Reset gridposition, when first line is not visible anymore
        If GridPosition <= -(Liqiang * 120) Then
            GridPosition = Liqiang
        End If
    End If
   
    'Draw line diagram only if theres 2 or more values defined
    If StartPosition <= 595 Then
        mem_pBox.ForeColor = mem_LineColor
        i = 119
        Select Case DiagramType
            Case TYPE_LINE
            For l = StartPosition + 5 To 590 Step Liqiang
                mem_pBox.Line (l, ValueArray(l / Liqiang))-(l + Liqiang, ValueArray(l / Liqiang + 1))
            Next
        End Select
        
    End If
End Sub
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


--------------------------------------------------------------------------------------------------------------------
本站是工控技术交流站点,论坛内容均为网络收集或会员所发表,并不代表本站立场,会员拥有该内容的所有权力及责任!
本站内容如有侵犯您的版权,请按下面方式联系本站管理员,我们将及时删除处理
管理员:冰糖 QQ:5483695(请直击主题), Mail:admin#ziwai.net(#改成@) 其它非本人.
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!

QQ|Archiver|手机版|小黑屋|紫外工控论坛. ( 苏ICP备11032118号-1 )

GMT+8, 2024-4-29 23:57 , Processed in 0.453131 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表