第一次写的曲线图控件代码

Public Class AClines

Inherits System.Windows.Forms.UserControl

 

'该组件将实现动态曲线的显示

'可以显示一条曲线,还可以显示多条曲线,并且曲线将可以移动也可一不移动

'可以设置组件的背景,组件上网格的行颜色和列颜色,

'可以设置横纵坐标的标识方式,(从左到右,还是从右到左),以及纵坐标的标识方式(从上到下,还是从下到上)

'可以设置横纵坐标的实际意义,还可以设置横纵表的字体颜色和大小

'可以设置曲线图的

 

#Region "变量的定义"

 

 

'Private a(150) As Double

'用于存储数据

Private bmData(1) As Double

Private bmDatas(,) As Double

'定义显示的数据的多少

Private bmDataNum As Integer = 1

 

 

Private margin_Top As Integer

Private margin_Bottom As Integer

Private margin_Left As Integer

Private margin_Right As Integer

 

 

Private bmWidth As Integer

Private bmHeight As Integer

 

Private flag As System.Drawing.Bitmap

 

Private bmbgColor As System.Drawing.Color

Private rowColor As System.Drawing.Color

Private colColor As System.Drawing.Color

 

 

Private bmMoveLine As Boolean

 

'定义横纵坐标的最大值和最小值

Private rowMaxValue As Integer

Private colMaxValue As Integer

Private rowMinValue As Integer

Private colMinValue As Integer

 

 

Private standardValues() As Integer

 

'定义偏移量和横纵坐标的偏移量

 

Private rowOffset As Integer

Private colOffset As Integer

 

'定义一个越界判定数组

Private sieveData() As Boolean

 

 

 

Private linePens() As System.Drawing.Pen

Private lineNum As Integer

 

 

 

#End Region

 

 

 

#Region "ACline属性定义区"

 

'曲线是否可以移动

Property MoveLine() As Boolean

Get

Return bmMoveLine

End Get

Set(ByVal Value As Boolean)

bmMoveLine = Value

Me.Timer1.Enabled = bmMoveLine

 

End Set

End Property

 

 

 

 

 

 

'======================================定义网格的所在位图的高宽_Begin==================

'位图的宽度,不同于组件自身的宽度

Property BitmapWidth() As Integer

Get

Return bmWidth

End Get

Set(ByVal Value As Integer)

bmWidth = Value

End Set

End Property

 

'位图的高度,不同于组件自身的宽度

Property BitmapHeight() As Integer

Get

Return bmHeight

End Get

Set(ByVal Value As Integer)

bmHeight = Value

End Set

End Property

'=========================================定义网格的所在位图的高宽_End==================

 

 

 

 

 

 

 

'===========================================定义涉及的颜色_Begin==================

'位图的背景色

Property BgColor() As System.Drawing.Color

Get

Return bmbgColor

End Get

Set(ByVal Value As System.Drawing.Color)

bmbgColor = Value

End Set

End Property

 

'网格的行颜色

Property RColor() As System.Drawing.Color

Get

Return rowColor

End Get

Set(ByVal Value As System.Drawing.Color)

rowColor = Value

End Set

End Property

 

'网格的列颜色

Property CColor() As System.Drawing.Color

Get

Return colColor

End Get

Set(ByVal Value As System.Drawing.Color)

colColor = Value

End Set

End Property

 

'============================================定义涉及的颜色_End========================

 

 

 

 

 

 

'=========================================标尺的单位长度的定义_Begin==================

 

'行偏移量的值,和最大值、最小值一样,是实际要显示的值

Property ROffset() As Integer

Get

Return rowOffset

End Get

Set(ByVal Value As Integer)

rowOffset = Value

End Set

End Property

 

'列偏移量的值(同上)

Property COffset() As Integer

Get

Return colOffset

End Get

Set(ByVal Value As Integer)

colOffset = Value

End Set

End Property

'=================================标尺的单位长度的定义_End====================

 

 

 

 

 

 

'================================标尺的大小值_Begin===========================

'行标尺(纵坐标)的最大值(为整型)

Property RMaxValue() As Integer

Get

Return rowMaxValue

End Get

Set(ByVal Value As Integer)

rowMaxValue = Value

End Set

End Property

 

'行标尺的最小值

Property RMinValue() As Integer

Get

Return rowMinValue

End Get

Set(ByVal Value As Integer)

rowMinValue = Value

End Set

End Property

 

'列标尺的最大值

Property CMaxValue() As Integer

Get

Return colMaxValue

End Get

Set(ByVal Value As Integer)

colMaxValue = Value

End Set

End Property

 

'列标尺的最小值

Property CMinValue() As Integer

Get

Return colMinValue

End Get

Set(ByVal Value As Integer)

colMinValue = Value

End Set

End Property

'===========================================标尺的大小值_End==========================

 

 

 

 

 

 

 

'=============================边界空白_Begin============================

'网格在位图上的边界空白

'上空白高度

Property MarginUP() As Integer

Get

Return margin_Top

End Get

Set(ByVal Value As Integer)

margin_Top = Value

End Set

End Property

 

 

'下空白

Property MarginBottom() As Integer

Get

Return margin_Bottom

End Get

Set(ByVal Value As Integer)

margin_Bottom = Value

End Set

End Property

 

'左空白

Property MarginLeft() As Integer

Get

Return margin_Left

End Get

Set(ByVal Value As Integer)

margin_Left = Value

End Set

End Property

 

'右空白

 

Property MarginRight() As Integer

Get

Return margin_Right

End Get

Set(ByVal Value As Integer)

margin_Right = Value

End Set

End Property

'=================================边界空白_End========================================

 

 

 

 

 

'===============================数据存储的大小设定_Begin========================

 

Property DataNum() As Integer

Get

Return bmDataNum

End Get

Set(ByVal Value As Integer)

bmDataNum = Value - 1

ReDim Preserve bmData(bmDataNum)

 

End Set

End Property

 

 

 

'===============================数据存储的大小设定_End===========================

#End Region

 

 

 

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

 

Public Sub New()

MyBase.New()

 

'该调用是 Windows 窗体设计器所必需的。

InitializeComponent()

 

'在 InitializeComponent() 调用之后添加任何初始化

 

End Sub

 

'UserControl1 重写 dispose 以清理组件列表。

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

 

'Windows 窗体设计器所必需的

Private components As System.ComponentModel.IContainer

 

'注意: 以下过程是 Windows 窗体设计器所必需的

'可以使用 Windows 窗体设计器修改此过程。

'不要使用代码编辑器修改它。

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

Friend WithEvents Timer1 As System.Windows.Forms.Timer

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container

Me.PictureBox1 = New System.Windows.Forms.PictureBox

Me.Timer1 = New System.Windows.Forms.Timer(Me.components)

Me.SuspendLayout()

'

'PictureBox1

'

Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Fill

Me.PictureBox1.Location = New System.Drawing.Point(0, 0)

Me.PictureBox1.Name = "PictureBox1"

Me.PictureBox1.Size = New System.Drawing.Size(488, 408)

Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage

Me.PictureBox1.TabIndex = 0

Me.PictureBox1.TabStop = False

'

'Timer1

'

Me.Timer1.Interval = 500

'

'AClines

'

Me.Controls.Add(Me.PictureBox1)

Me.Name = "AClines"

Me.Size = New System.Drawing.Size(488, 408)

Me.ResumeLayout(False)

 

End Sub

 

#End Region

 

#Region "图形初始化使用到的数据的预处理"

 

Private Sub InitBitmap()

 

 

'=================================创建画布位图==================================================================

'检查位图的大小

 

If (bmWidth < 0 Or bmHeight < 0) Then

bmWidth = 100

bmHeight = 100

ElseIf (bmWidth > 0 And bmHeight > 0) Then

bmWidth = bmWidth

bmHeight = bmHeight

Else

bmWidth = Me.PictureBox1.Width

bmHeight = Me.PictureBox1.Height

End If

 

'正式创建位图

flag = New System.Drawing.Bitmap(bmWidth, bmHeight)

 

 

 

'=============================网格错误输入的校正========================================

 

If (margin_Left <= 0 And margin_Bottom <= 0 And margin_Left <= 0 And margin_Right <= 0) Then

 

margin_Top = 10

margin_Bottom = 20

margin_Left = 20

margin_Right = 10

End If

 

 

 

 

 

 

'===============================对最大值和最小值输入出错时的校正========================

 

 

If rowMaxValue < rowMinValue Then

rowMaxValue = rowMaxValue + rowMinValue

rowMinValue = rowMaxValue - rowMinValue

rowMaxValue = rowMaxValue - rowMinValue

End If

 

 

If colMaxValue < rowMinValue Then

colMaxValue = colMaxValue + colMinValue

colMinValue = colMaxValue - colMinValue

colMaxValue = colMaxValue - colMinValue

End If

 

If rowOffset <= 0 Then

rowOffset = (rowMaxValue - rowMinValue) / 10

End If

 

If colOffset <= 0 Then

colOffset = (colMaxValue - colMinValue) / 10

End If

 

 

 

'================================对默认网格的背景颜色以及横纵线颜色处理==============================================

 

If bmbgColor.Equals(Color.Empty) Then

bmbgColor = Color.GhostWhite

End If

 

If rowColor.Equals(Color.Empty) Then

rowColor = Color.Green

End If

 

If colColor.Equals(Color.Empty) Then

colColor = Color.Green

End If

 

 

 

'================================对要显示的数据数组初始化===================================================================

 

If bmDataNum <= 0 Then

bmDataNum = 10

ReDim Preserve bmData(bmDataNum)

End If

 

If lineNum < 1 Then

lineNum = 1

End If

 

ReDim Preserve bmDatas(lineNum, bmDataNum)

 

'================================滤波数据的处理===================================================================

ReDim Preserve sieveData(bmDataNum)

'Dim i As Integer

''For i = 0 To sieveData.Length - 1

'' sieveData(i) = True

''Next

 

 

''====================================================================

''计划作为属性来处理

''供测试使用

'rowOffset = 10

'colOffset = 1

 

'margin_Top = 10

'margin_Bottom = 20

'margin_Left = 35

'margin_Right = 20

 

 

'rowMaxValue = 100

'rowMinValue = -100

'colMaxValue = 100

'colMinValue = 1

 

''====================================================================

 

''====================================================================

''计划作为属性来处理

''供测试使用

'bmbgColor = Color.GhostWhite

'colColor = Color.HotPink

'rowColor = Color.HotPink

''====================================================================

 

 

End Sub

 

#End Region

 

#Region "图形中常用到的图像处理方法"

 

'位图上画直线

Private Sub Bitmapline(ByRef flag As System.Drawing.Bitmap, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal mypen As System.Drawing.Pen)

 

Dim mypic As System.Drawing.Graphics

'Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)

mypic = System.Drawing.Graphics.FromImage(flag)

mypic.DrawLine(mypen, x1, y1, x2, y2)

'最后才能把画笔取消掉

'mypen.Dispose()

mypic.Dispose()

End Sub

 

 

 

'位图上写横字

Private Sub BitmapwordH(ByRef flag As System.Drawing.Bitmap, ByVal x As Integer, ByVal y As Integer, ByVal word As String)

Dim mypic As System.Drawing.Graphics

Dim drawFont As New System.Drawing.Font("Arial", 8)

Dim drawBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Black)

Dim drawFormat As New System.Drawing.StringFormat

'drawFormat.FormatFlags = StringFormatFlags.DirectionVertical

mypic = System.Drawing.Graphics.FromImage(flag)

mypic.DrawString(word, drawFont, drawBrush, x, y, drawFormat)

drawFont.Dispose()

drawBrush.Dispose()

mypic.Dispose()

End Sub

 

'位图上写纵字

Private Sub BitmapwordV(ByRef flag As System.Drawing.Bitmap, ByVal x As Integer, ByVal y As Integer, ByVal word As String)

Dim mypic As System.Drawing.Graphics

Dim drawFont As New System.Drawing.Font("Arial", 8)

Dim drawBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Black)

Dim drawFormat As New System.Drawing.StringFormat

drawFormat.FormatFlags = StringFormatFlags.DirectionVertical

mypic = System.Drawing.Graphics.FromImage(flag)

mypic.DrawString(word, drawFont, drawBrush, x, y, drawFormat)

drawFont.Dispose()

drawBrush.Dispose()

mypic.Dispose()

End Sub

 

 

 

 

 

#End Region

 

#Region "生成曲线的方法"

 

 

'创建一个网格图

Private Sub CreateTable(ByRef flag As System.Drawing.Bitmap, ByVal bmWidth As Integer, ByVal bmHeight As Integer)

'绘制位图

Dim x As Integer

Dim y As Integer

' 处理位图的高和宽

If (bmWidth < 0 Or bmHeight < 0) Then

bmWidth = 100

bmHeight = 100

ElseIf (bmWidth > 0 And bmHeight > 0) Then

bmWidth = bmWidth

bmHeight = bmHeight

Else

bmWidth = Me.PictureBox1.Width

bmHeight = Me.PictureBox1.Height

End If

'创建位图

flag = New System.Drawing.Bitmap(bmWidth, bmHeight)

 

'====================================================================

'计划作为属性来处理

'供测试使用

bmbgColor = Color.GhostWhite

rowColor = Color.Green

colColor = Color.Green

rowOffset = -20

colOffset = 20

 

margin_Top = 20

 

margin_Top = 20

margin_Bottom = 30

margin_Left = 30

margin_Right = 20

 

'====================================================================

 

 

'先设置背景颜色

For x = 0 To flag.Width - 1

For y = 0 To flag.Height - 1

flag.SetPixel(x, y, bmbgColor)

Next

Next

 

'=============================横纵坐标的处理========================================

'先判断margin

If (margin_Top < 0 Or margin_Bottom < 0 Or margin_Left < 0 Or margin_Right < 0) Then

margin_Top = 0

margin_Bottom = 0

margin_Left = 0

margin_Right = 0

 

End If

 

 

'创建横纵坐标

'行偏移为负值时,横坐标在下

If (rowOffset >= 0) Then

For x = margin_Left To flag.Width - margin_Right - 1

For y = margin_Top To flag.Height - margin_Bottom - 1 Step rowOffset

flag.SetPixel(x, y, rowColor)

Next

Next

Else

For x = margin_Left To flag.Width - margin_Right - 1

For y = flag.Height - margin_Bottom - 1 To margin_Top Step rowOffset

flag.SetPixel(x, y, rowColor)

Next

Next

End If

If (colOffset >= 0) Then

For x = margin_Left To flag.Width - margin_Right - 1 Step colOffset

For y = margin_Top To flag.Height - margin_Bottom - 1

flag.SetPixel(x, y, colColor)

Next

 

Next

Else

For x = margin_Left To flag.Width - margin_Right - 1 Step colOffset

For y = margin_Top To flag.Height - margin_Bottom - 1

flag.SetPixel(x, y, colColor)

Next

 

Next

End If

 

 

'======================================================================

PictureBox1.Image = flag

End Sub

 

' 创建标尺(没有负数的情况)

 

Private Sub CreateRuler(ByRef flag As System.Drawing.Bitmap)

Dim x As Integer

Dim y As Integer

 

 

'====================================================================

'计划作为属性来处理

'供测试使用

rowOffset = -20

colOffset = 20

 

margin_Top = 20

margin_Bottom = 30

margin_Left = 30

margin_Right = 20

 

'====================================================================

 

'写横坐标操作

If (rowOffset >= 0) Then

For x = margin_Left To flag.Width - margin_Right - 1 Step rowOffset

BitmapwordH(flag, x, 15, (x - margin_Left).ToString())

Next

Else

For x = margin_Left To flag.Width - margin_Right - 1 Step -(rowOffset)

BitmapwordH(flag, x, flag.Height - margin_Bottom, (x - margin_Left).ToString())

Next

 

End If

 

'写纵坐标

If (rowOffset >= 0) Then

For y = margin_Top To flag.Height - margin_Bottom - 1 Step colOffset

BitmapwordH(flag, 0, (y + margin_Top), (y - margin_Top).ToString() + "Y")

Next

Else

For y = flag.Height - margin_Bottom - 1 To margin_Top Step -(colOffset)

BitmapwordH(flag, 0, y, (flag.Height - margin_Bottom - 1 - y).ToString() + "Y")

Next

 

End If

 

 

 

End Sub

 

 

'创建具有负数的标尺

Private Sub CreateRuler2(ByRef flag As System.Drawing.Bitmap)

Dim x As Integer

Dim y As Integer

 

Dim xParent As Double

Dim yParent As Double

Dim xLength As Integer 'y轴的实际长度(去掉边界空白)

Dim yLength As Integer 'x轴的实际长度

Dim xScale As Integer 'y轴要显示的范围(最大值和最小值的差)

Dim yScale As Integer 'x轴要显示的范围

 

Dim realX As Integer '主要用于在显示数据时控制,数据的实际坐标

Dim realY As Integer

 

'计算画布的可用尺寸

yLength = flag.Height - margin_Bottom - margin_Top - 1

xLength = flag.Width - margin_Left - margin_Right - 1

 

'计算画布要表示的数值范围,从而计算比例定位数据

xScale = colMaxValue - colMinValue

yScale = rowMaxValue - rowMinValue

'创建横坐标

For x = colMinValue To colMaxValue Step colOffset

xParent = (x - colMinValue) / xScale

realX = CInt(xLength * xParent) + margin_Left

BitmapwordH(flag, realX, flag.Height - margin_Bottom, x.ToString())

Next

 

'创建纵坐标

For y = rowMinValue To rowMaxValue Step rowOffset

yParent = (y - rowMinValue) / yScale

realY = CInt(yLength * yParent) + margin_Top

realY = flag.Height - margin_Bottom - realY + margin_Top

 

BitmapwordH(flag, 0, realY, y.ToString())

Next

 

End Sub

 

'创建表使用画直线的方法来画网格

Private Sub CreateTable()

 

Dim x As Integer

Dim y As Integer

 

Dim xParent As Double

Dim yParent As Double

Dim xLength As Integer 'y轴的实际长度(去掉边界空白)

Dim yLength As Integer 'x轴的实际长度

Dim xScale As Integer 'y轴要显示的范围(最大值和最小值的差)

Dim yScale As Integer 'x轴要显示的范围

 

Dim realX As Integer '主要用于在显示数据时控制,数据的实际坐标

Dim realY As Integer

 

Dim xStart As Integer '用来记录横纵坐标的开始和结束值

Dim xEnd As Integer

Dim yStart As Integer

Dim yEnd As Integer

 

 

flag = New System.Drawing.Bitmap(bmWidth, bmHeight)

 

 

 

 

'先设置背景颜色

For x = 0 To flag.Width - 1

For y = 0 To flag.Height - 1

flag.SetPixel(x, y, bmbgColor)

Next

Next

 

 

'这里计算我们画布的可用尺寸

yLength = flag.Height - margin_Bottom - margin_Top - 1

xLength = flag.Width - margin_Left - margin_Right - 1

 

xScale = colMaxValue - colMinValue

yScale = rowMaxValue - rowMinValue

 

yStart = margin_Top

yEnd = flag.Height - margin_Bottom

xStart = margin_Left

xEnd = flag.Width - margin_Right

 

 

'创建纵向线

For x = colMinValue To colMaxValue Step colOffset

xParent = (x - colMinValue) / xScale

realX = CInt(xLength * xParent) + margin_Left

Bitmapline(flag, realX, yStart, realX, yEnd, New System.Drawing.Pen(rowColor))

Next

 

'创建横向线

For y = rowMinValue To rowMaxValue Step rowOffset

yParent = (y - rowMinValue) / yScale

realY = CInt(yLength * yParent) + margin_Top

realY = flag.Height - margin_Bottom - realY + margin_Top

Bitmapline(flag, xStart, realY, xEnd, realY, New System.Drawing.Pen(colColor))

Next

 

PictureBox1.Image = flag

 

End Sub

 

 

'位图上画曲线(具体数据考虑)

Private Sub bitmapacline(ByRef flag As System.Drawing.Bitmap, ByVal a() As Integer, ByRef mypen() As System.Drawing.Pen)

Dim realY As Integer

Dim realX As Integer

Dim xParent As Double

Dim yParent As Double

Dim b() As Integer

 

Dim i As Integer

Static j As Integer

 

For i = a.Length - 1 To 1 Step -1

a(i) = a(i - 1)

Next

j = j + 10

If j > 260 Then j = 0

a(i) = j

 

For i = 1 To a.Length - 1

'bitmapline(flag, (i - 1) * 10, a(i - 1), i * 10, a(i))

Bitmapline(flag, (i - 1 + 1) * 20, a(i - 1), (i + 1) * 20, a(i), mypen(0))

Next

 

'横坐标从左到右,纵坐标从上到下

'处理数据值

'测试时期使用固定的最大值和最小值为picturebox的大小减去margin得到的

rowMaxValue = flag.Height - margin_Bottom - 1

rowMinValue = 0

 

ReDim Preserve b(a.Length - 1)

 

 

For i = 0 To a.Length - 1

yParent = a(i) / (rowMaxValue - rowMinValue)

xParent = i

 

b(i) = CInt((flag.Height - margin_Bottom - 1) * yParent)

b(i) = flag.Height - margin_Bottom - 1 - b(i)

Next

 

For i = 1 To a.Length - 1

 

 

Bitmapline(flag, (i - 1 + 1) * 20, b(i - 1), (i + 1) * 20, b(i), mypen(1))

 

Next

 

End Sub

 

'位图上画曲线的第二个版本(从左到右)

Private Sub CreateACline(ByRef flag As System.Drawing.Bitmap, ByVal a() As Double, ByVal toRight As Boolean, ByVal bmPen As System.Drawing.Pen)

Dim i As Integer

 

 

If toRight Then

For i = 1 To a.Length - 1

Bitmapline(flag, XDataProcess(i - 1, a), a(i - 1), XDataProcess(i, a), a(i), bmPen)

Next

Else

 

For i = 1 To a.Length - 1

Bitmapline(flag, XDataProcessR2L(i - 1, a), a(i - 1), XDataProcessR2L(i, a), a(i), bmPen)

Next

End If

 

PictureBox1.Image = flag

End Sub

 

 

 

#End Region

 

#Region "图形中常用到的数据处理方法"

 

'===============================================================================================

'处理数据的显示(按比例在位图上进行显示)-Begin

'===============================================================================================

 

'---------------------------------------------------------------------------------------

' 1.ID : XDataProcess

' 2.Input Value : i 横坐标数组的值,x()为横坐标数组

' 3.Return Value : Integer

' 4.Create Date : 2008.7.11 Write By ITelite

' 5.Modify Date :

' 6.Comment : 处理横坐标的值

'---------------------------------------------------------------------------------------

Private Function YDataProcess(ByVal realData As Double) As Integer

 

Dim i As Integer

Dim yParent As Double

Dim yLength As Integer 'x轴的实际长度

Dim yScale As Integer 'x轴要显示的范围

Dim realY As Integer '主要用于在显示数据时控制,数据的实际坐标

 

'使用一种比较简单的处理方式来处理滤波

If realData > rowMaxValue Then

realData = rowMaxValue

ElseIf realData < rowMinValue Then

realData = rowMinValue

End If

 

yLength = flag.Height - margin_Bottom - margin_Top - 1

yScale = rowMaxValue - rowMinValue

 

 

yParent = (realData - rowMinValue) / yScale

realY = CInt(yLength * yParent) + margin_Top

realY = flag.Height - margin_Bottom - 1 - realY + margin_Top

 

YDataProcess = realY

 

End Function

 

'---------------------------------------------------------------------------------------

' 1.ID : XDataProcess

' 2.Input Value : i 横坐标数组的值,x()为横坐标数组

' 3.Return Value : Integer

' 4.Create Date : 2008.7.11 Write By ITelite

' 5.Modify Date :

' 6.Comment : 处理横坐标的值

'---------------------------------------------------------------------------------------

 

Private Function XDataProcess(ByVal i As Integer, ByVal x() As Double) As Integer

 

Dim xParent As Double

Dim xLength As Integer

Dim xScale As Integer

Dim realX As Integer

 

 

 

xLength = flag.Width - margin_Left - margin_Right - 1

xScale = x.Length - 1

xParent = i / xScale

realX = CInt(xLength * xParent) + margin_Left

 

XDataProcess = realX

 

End Function

 

Private Function XDataProcessR2L(ByVal i As Integer, ByVal x() As Double) As Integer

 

Dim xParent As Double

Dim xLength As Integer

Dim xScale As Integer

Dim realX As Integer

 

 

 

xLength = flag.Width - margin_Left - margin_Right - 1

xScale = x.Length - 1

xParent = i / xScale

realX = CInt(xLength * xParent) + margin_Left

realX = flag.Width - margin_Right - 1 - realX + margin_Left

 

XDataProcessR2L = realX

 

End Function

 

 

'===============================================================================================

'处理数据的显示(按比例在位图上进行显示)-End

'===============================================================================================

 

 

 

 

'用来使数据循环起来

 

 

 

Private Sub MoveData(ByRef a() As Double)

Dim i As Integer

For i = a.Length - 1 To 1 Step -1

a(i) = a(i - 1)

Next

End Sub

 

Private Sub MoveData(ByRef a() As Integer)

Dim i As Integer

For i = a.Length - 1 To 1 Step -1

a(i) = a(i - 1)

Next

End Sub

 

Private Sub MoveData(ByRef a() As Boolean)

Dim i As Integer

For i = a.Length - 1 To 1 Step -1

a(i) = a(i - 1)

Next

End Sub

 

 

Private Sub MoveData(ByRef a(,) As Double)

Dim i As Integer

Dim j As Integer

 

For i = 0 To bmDatas.GetUpperBound(0)

 

For j = bmDatas.GetUpperBound(1) To 1 Step -1

bmDatas(i, j) = bmDatas(i, j - 1)

Next

 

Next

 

End Sub

 

#End Region

 

 

 

 

#Region "附加功能"

 

'---------------------------------------------------------------------------------------

' 1.ID : BitmapwordH

' 2.Input Value :

' 3.Return Value : Boolean

' 4.Create Date : 2008.7.11 Write By ITelite

' 5.Modify Date :

' 6.Comment : 位图上写横字

'---------------------------------------------------------------------------------------

 

 

 

 

'画曲线

Public Sub DynamicACLines(ByRef a() As Integer)

lineNum = 2

ReDim linePens(lineNum - 1)

linePens(0) = New System.Drawing.Pen(System.Drawing.Color.Red)

linePens(1) = New System.Drawing.Pen(System.Drawing.Color.Blue)

bitmapacline(flag, a, linePens)

End Sub

 

 

'画中线

Private Sub CreateStandardLine(ByVal standardValues() As Integer)

Dim i As Integer

Dim xStart As Integer

Dim XEnd As Integer

 

Dim dashPen As New System.Drawing.Pen(Color.Red, 2)

dashPen.DashStyle = Drawing2D.DashStyle.Dash

 

 

 

xStart = margin_Left

XEnd = flag.Width - margin_Right

 

For i = 0 To standardValues.Length - 1

standardValues(i) = YDataProcess(standardValues(i))

Next

 

For i = 0 To standardValues.Length - 1

Bitmapline(flag, xStart, standardValues(i), XEnd, standardValues(i), dashPen)

 

Next

End Sub

'========================写标题_Begin===========================================

Private Sub bmTitle(ByVal title As String)

Dim x As Integer

Dim y As Integer

Dim xLength As Integer

xLength = flag.Width - margin_Left - margin_Right - 1

x = (xLength - Len(title) * 10) / 2

 

 

BitmapwordH(flag, x, 5, title)

End Sub

'========================写标题_End=========================================================

 

 

 

 

 

#End Region

 

 

#Region "发布的方法"

 

Public Sub CreateGrid()

InitBitmap()

'CreateTable()

'bmTitle("性能优化实例")

'CreateRuler2(flag)

End Sub

 

 

Public Sub showimage(ByVal displayValue As Double, ByVal L2R As Boolean, ByVal a() As Integer)

'先初始化位图的画布

InitBitmap()

 

 

 

'准备数据

 

bmData(0) = YDataProcess(displayValue)

 

CreateTable()

CreateStandardLine(a)

bmTitle("动态曲线实例")

CreateRuler2(flag)

CreateACline(flag, bmData, L2R, New System.Drawing.Pen(Color.Red))

End Sub

 

'不画基线的图

Public Sub showimage(ByVal displayValue As Double, ByVal L2R As Boolean)

'先初始化位图的画布

'InitBitmap()

'准备数据

MoveData(bmData)

bmData(0) = YDataProcess(displayValue)

 

CreateTable()

bmTitle("动态曲线实例")

CreateRuler2(flag)

CreateACline(flag, bmData, L2R, New System.Drawing.Pen(Color.Red))

End Sub

 

 

Public Sub ShowImages(ByVal displayValue() As Double, ByVal L2R As Boolean, ByRef mypen() As System.Drawing.Pen)

Dim i As Integer

Dim j As Integer

 

'用于存储数据的临时数组

Dim tempData() As Double

'Prepare the Two

MoveData(bmDatas)

bmDatas(0, 0) = YDataProcess(displayValue(0))

bmDatas(1, 0) = YDataProcess(displayValue(1))

 

CreateTable()

bmTitle("动态曲线实例")

CreateRuler2(flag)

 

For i = 0 To bmDatas.GetUpperBound(0)

ReDim tempData(bmDatas.GetUpperBound(1))

For j = 0 To bmDatas.GetUpperBound(1)

tempData(j) = bmDatas(i, j)

Next

CreateACline(flag, tempData, L2R, mypen(i))

Next

 

End Sub

 

 

#End Region

 

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

CreateTable()

CreateRuler2(flag)

'CreateACline(flag, New System.Drawing.Pen(Color.Green))

'DynamicACLines(a)

 

'Dim i As Integer

'Dim m(10) As Double

'Dim n(10) As Double

'm(0) = -100

'n(0) = v

'For i = 1 To m.Length - 1

' m(i) = i * 100

' n(i) = i * 100

'Next

 

 

 

 

' CreateStandardLine(flag)

 

End Sub

End Class

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值