加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

实时曲线图(类似Delphi中是Chart控件)[一]

(2007-05-27 21:49:17)
分类: 原创控件
    我最近在赶做一个台架试验数据处理系统,是一个实时记录试验数据的数据库程序,想用实时曲线同时直观的反映各个数据的变化情况,可惜VB中没有DELPHI中的CHART那样的控件(也可能是我没找到),于是费尽九牛二虎之力做了一个,先发个测试时的截图吧
实时曲线图(类似Delphi中是Chart控件)[一] 
    先添加一个用户控件,分别添加一个Panel(ShowAreaPNL),GroupBox(GroupBox1),CheckBox(AutoScrollCHB),两个RadioBox(ActualKindRDB,StaticKindRDB),布局如上图.
    以下是代码的实现:
 

mports System
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms

'<Serializable(), DefaultProperty(" ItemsV")> _
Public Class ActualCurveChart
    Inherits System.Windows.Forms.Panel

#Region "  内部嵌套类型定义:ItemV、ItemVCollection  "
    Enum ChartKindEnum
        ckStaticKind
        ckActualKind
    End Enum
    <Serializable(), TypeConverter(GetType(ComponentConverter))> _
    Public Class ItemV
        Inherits UserControl
        Private _MinValue As Single = 0
        Private _MaxValue As Single = 100
        Private _Unit As String = ""

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), Browsable(True)> _
        Overrides Property Text() As String
            Get
                Return MyBase.Text
            End Get
            Set(ByVal Value As String)
                MyBase.Text = Value
                Me.Refresh()
            End Set
        End Property
        <DefaultValue(GetType(Single), "0")> _
        Property MinValue() As Single
            Get
                Return _MinValue
            End Get
            Set(ByVal Value As Single)
                _MinValue = Value
            End Set
        End Property
        <DefaultValue(GetType(Single), "100")> _
        Property MaxValue() As Single
            Get
                Return _MaxValue
            End Get
            Set(ByVal Value As Single)
                _MaxValue = Value
            End Set
        End Property

        Property Unit() As String
            Get
                Return _Unit
            End Get
            Set(ByVal Value As String)
                _Unit = Value
            End Set
        End Property

#Region " Windows 窗体设计器生成的代码 "

       ...

#End Region

        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            Dim G As Graphics, intTxtSize As Size, sf As New StringFormat(StringFormatFlags.DirectionVertical)
            G = e.Graphics
            intTxtSize = Size.Ceiling(G.MeasureString(MaxValue.ToString.Trim, Me.Font))
            G.DrawString(MaxValue.ToString.Trim, Me.Font, New SolidBrush(Me.ForeColor), CSng((Me.Width - intTxtSize.Height) / 2), 0, sf)

            intTxtSize = Size.Ceiling(G.MeasureString(Me.Text.Trim & "(" & Me.Unit & ")", Me.Font))
            G.DrawString(Me.Text.Trim & "(" & Me.Unit & ")", Me.Font, New SolidBrush(Me.ForeColor), CSng((Me.Width - intTxtSize.Height) / 2), CSng((Me.Height - intTxtSize.Width) / 2), sf)

            intTxtSize = Size.Ceiling(G.MeasureString(MinValue.ToString.Trim, Me.Font))
            G.DrawString(MinValue.ToString.Trim, Me.Font, New SolidBrush(Me.ForeColor), CSng((Me.Width - intTxtSize.Height) / 2), Me.Height - intTxtSize.Width, sf)
        End Sub
    End Class
    <TypeConverterAttribute(GetType(ControlCollection))> _
    Public Class ChartItemVCollection
        Inherits CollectionBase
        Event MemberChanged(ByVal Sender As ChartItemVCollection)
        Default Public Property Item(ByVal index As Integer) As ItemV
            Get
                Return CType(list(index), ItemV)
            End Get
            Set(ByVal Value As ItemV)
                list(index) = Value
            End Set
        End Property 'Item
        Public Function Add(ByVal value As ItemV) As Integer
            Dim i As Integer
            i = list.Add(value)
            Return i
        End Function 'Add

        Public Function IndexOf(ByVal value As ItemV) As Integer
            Return list.IndexOf(value)
        End Function 'IndexOf
        Public Sub Insert(ByVal Index As Integer, ByVal value As ItemV)
            list.Insert(Index, value)
        End Sub 'Insert
        Public Sub Remove(ByVal value As ItemV)
            Try
                list.Remove(value)
            Catch ex As Exception
                Exit Sub
            End Try
        End Sub 'Remove

        Public Function Contains(ByVal value As ItemV) As Boolean
            '如果value的类型不是ItemV,这里将返回False
            Return list.Contains(value)
        End Function 'Contains
        Protected Overrides Sub OnClearComplete()
            RaiseEvent MemberChanged(Me)
        End Sub
        Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object)
            RaiseEvent MemberChanged(Me)
        End Sub
        Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object)
            If Not value.GetType() Is Type.GetType("CtrlLIB.ActualCurveChart+ItemV") Then
                Throw New ArgumentException("Value must be of type ItemV", "Value")
            End If
        End Sub 'OnInsert
        Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object)
            RaiseEvent MemberChanged(Me)
        End Sub
        Protected Overrides Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object)
            If Not newValue.GetType() Is Type.GetType("CtrlLIB.ActualCurveChart+ItemV") Then
                Throw New ArgumentException("Value must be of type ItemV", "NewValue")
            End If
        End Sub 'OnSet
        Protected Overrides Sub OnSetComplete(ByVal index As Integer, ByVal oldvalue As Object, ByVal newvalue As Object)
            RaiseEvent MemberChanged(Me)
        End Sub
        Protected Overrides Sub OnValidate(ByVal value As Object)
            If Not value.GetType() Is Type.GetType("CtrlLIB.ActualCurveChart+ItemV") Then
                Throw New ArgumentException("Value must be of type ItemV")
            End If
        End Sub 'OnValidate

    End Class 'ChartItemVCollection
#End Region

 

 

实时曲线图(类似Delphi中是Chart控件)[二]

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有