实时曲线控件(2)

  
在上一个实例中我们采用两个picturebox1,这次我们只采用一个picturebox1来继续画展图,这样就更简单了。
Dim MaxPlotNo As Long  '最长的X轴范围

    Dim SDataPonit() As PointF  '显示图像
    Dim HdataPonit(20) As PointF

    Dim DId As Long      '序号

    '  Dim YMin As Single = 99999.9, YMax As Single = -99999.9
    Dim ScaleFactorX, ScaleFactorY As Single
    Dim pScalex, pScaley As Single

    Dim wid As Integer         '图像的宽度
    Dim hgt As Integer         '图像的高度
    Dim bm As Image
    Dim gr As Graphics

    '在隐形窗体上作画,画好以后再显示在显示
    Private Function PlotData(ByVal PointArray() As PointF) As Boolean

        Dim RedPen As New Pen(Color.Red), MPen As New Pen(Color.Blue), LPointArray(), LBaseArray(1) As PointF

        Dim bm2 As New Bitmap(wid, hgt)  '建立背景绘图区
        Dim gr2 As Graphics = Graphics.FromImage(bm2) '建立绘图的画布

        Dim pen As Pen = New Pen(Color.Green)
        pen.DashStyle = Drawing2D.DashStyle.Dot

        For i As Integer = 0 To hgt Step 20
            gr2.DrawLine(pen, 0, i, wid, i)
        Next

        For i As Integer = 0 To wid Step 20
            gr2.DrawLine(pen, i, 0, i, hgt)
        Next

        ReDim LPointArray(PointArray.GetUpperBound(0)) '重订区域阵列变数范围
        ' 最小X值()
        DisplaylblStartX(DId - MaxPlotNo + PointArray(PointArray.GetLowerBound(0)).X.ToString("0.00"))
        '最大X值
        DisplaylblEndX(DId - MaxPlotNo + PointArray(PointArray.GetUpperBound(0)).X.ToString("0.00"))

        '取得阵列的极限值
        'For i As Integer = PointArray.GetLowerBound(0) To PointArray.GetUpperBound(0)
        '    If PointArray(i).Y > YMax Then YMax = PointArray(i).Y
        '    If PointArray(i).Y < YMin Then YMin = PointArray(i).Y
        'Next

        'DisplaylblStartY(YMin.ToString("0"))  '最小Y值
        'DisplaylblEndY(YMax.ToString("0"))  '最大Y值

        '填入阵列元素
        For i As Integer = PointArray.GetLowerBound(0) To PointArray.GetUpperBound(0)
            LPointArray(i).X = PointArray(i).X * pScalex
            '和上方Y零点的距离
            LPointArray(i).Y = PointArray(i).Y
        Next

        gr2.DrawLines(RedPen, LPointArray) '绘图
        '将背景绘图资料放到图片框中
         PicShow.Image = bm2
        '重新显示
        gr2.Dispose()  '清除画布
        RedPen.Dispose() '清除资源

    End Function

    Sub Plot(ByVal StartX As Single)

        ReDim Preserve SDataPonit(DId)
        SDataPonit(DId).X = DId * pScalex
        SDataPonit(DId).Y = StartX * pScaley

        If DId < MaxPlotNo Then

            If DId > 1 Then
                gr.DrawLine(Pens.Red, SDataPonit(DId - 1), SDataPonit(DId))
            End If
            DisplayPic(bm)
        Else
            For i As Integer = 0 To MaxPlotNo

                HdataPonit(i).X = i ' + DId - 20
                HdataPonit(i).Y = SDataPonit(i + DId - 20).Y

            Next

            PlotData(HdataPonit)

        End If

        DId = DId + 1

    End Sub

    Private Sub UcRealCurs_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        wid = PicShow.ClientSize.Width
        hgt = PicShow.ClientSize.Height
        bm = New Bitmap(wid, hgt)  '建立背景绘图区
        gr = Graphics.FromImage(bm) '建立绘图的画布
        MaxPlotNo = 20
        Dim pen As Pen = New Pen(Color.Green)
        pen.DashStyle = Drawing2D.DashStyle.Dot

        For i As Integer = 0 To hgt Step 20
            gr.DrawLine(pen, 0, i, wid, i)
        Next

        For i As Integer = 0 To wid Step 20
            gr.DrawLine(pen, i, 0, i, hgt)
        Next

        ScaleFactorX = MaxPlotNo
        ScaleFactorY = 200
        pScalex = PicShow.Width / ScaleFactorX             'X轴的比例系数
        pScaley = (PicShow.Height * 0.97) / ScaleFactorY   'Y轴的比例系数

    End Sub


在实时曲线1中,我采用的两个picturebox1,其实认真分析,发现只要采用一个picturebox1就可以了。详细不用说,直接挂程序

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值