一个简单的组件开发源码(自定义Picturebox)
来源:互联网 发布:罗辑思维人工智能 编辑:程序博客网 时间:2024/05/19 23:11
Public Class SensorPictureBox Public IsFirstRun As Boolean = True Private _IsResultPainted As Boolean Private _Value() As Double Private _SensorReading(,) As Double = Nothing '{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}} Public Sub New() '重载消息处理事件。 ' 重载窗口寸改变事件 '重载窗口绘制事件
Option Strict On
Option Explicit On
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Inherits UserControl
Public Property IsResultPainted() As Boolean
Get
Return _IsResultPainted
End Get
Set(ByVal value As Boolean)
_IsResultPainted = value
End Set
End Property
Public Property Value() As Double()
Get
Return _Value
End Get
Set(ByVal value As Double())
_Value = value
If Not IsResultPainted Then Me.Invalidate(False)
End Set
End Property
Public Property SensorReading() As Double(,)
Get
Return _SensorReading
End Get
Set(ByVal value As Double(,))
_SensorReading = value
Me.Invalidate(False)
End Set
End Property
InitializeComponent()
Me.BorderStyle = Windows.Forms.BorderStyle.Fixed3D '设置窗体为凹陷的效果
SensorReading = _SensorReading
Me.AccessibleDescription = "Peter Jiang from LiteON."
'最简单的实现双缓冲绘图
'AllPaintingInWmPaint 忽略系统消息,防止图像闪烁
'DoubleBuffer 设置双缓冲,防止图像抖动
'UserPaint 自己为 控件做所有的绘图操作
'Opaque 使窗体绘制时,不绘制背景
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer Or ControlStyles.Opaque, True)
'更新风格
Me.UpdateStyles()
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H14 Then
Return
End If
MyBase.WndProc(m)
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Me.Invalidate(False)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
'绘制外框
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), Me.ClientRectangle)
If IsFirstRun Then Exit Sub
' 加入在線段或曲線的起始圖形
Dim startGP As New GraphicsPath()
'加入四條直線
startGP.AddEllipse(-1, -1, 2, 2)
' 封裝線條端點
Dim start_cap As New CustomLineCap(Nothing, startGP)
Dim clPen As New Pen(Color.Green, 2)
Dim ResultPen As New Pen(Color.Cyan, 2)
Dim lPen As New Pen(Color.Blue, 1.5)
Dim font As New Font("Consolas", 10, FontStyle.Regular)
'設定線段或曲線的開始樣式
ResultPen.CustomStartCap = start_cap
Dim X, Y As Integer
Dim count As Integer = Value.Count - 1
Dim Points(count) As Point
For i As Integer = 0 To count Step 1
X = 90 * i + 20
Y = CInt(Value(i) * 100)
Points(i) = New Point(X, Y)
e.Graphics.DrawString(Value(i).ToString("0.000"), font, _
Brushes.BlueViolet, X - 10, Me.Height - 24)
Next
e.Graphics.DrawLine(clPen, 0, CInt(Me.Height / 2), Me.Width, CInt(Me.Height / 2))
For i As Integer = 0 To count - 1
'設定線段或曲線的結束樣式
If i = count - 1 Then ResultPen.CustomEndCap = start_cap
e.Graphics.DrawLine(ResultPen, Points(i), Points(i + 1))
Next
If Not IsResultPainted Then Exit Sub
For iX As Integer = 0 To count Step 1
X = 90 * iX + 20
For iY As Integer = 0 To 1
Dim Y0 As Integer = CInt(SensorReading(iX, iY) * 100)
Dim Y1 As Integer = CInt(SensorReading(iX, iY + 1) * 100)
e.Graphics.DrawLine(lPen, X, Y0, X, Y1)
Select Case iY
Case 0
e.Graphics.DrawImage(My.Resources.Sensor_Start, New Rectangle(X - 4, Y0 - 4, 8, 8))
e.Graphics.DrawImage(My.Resources.Sensor_Nom, New Rectangle(X - 4, Y1 - 4, 8, 8))
Case 1
e.Graphics.DrawImage(My.Resources.Sensor_End, New Rectangle(X - 3, Y1 - 3, 6, 6))
End Select
Next
Next
End Sub
End Class
- 一个简单的组件开发源码(自定义Picturebox)
- ASP.NET自定义控件组件开发 第一章:从一个简单的控件谈起
- 简单的Ext自定义组件
- Android自定义组件:一个波浪形的组件
- Extjs的一个自定义组件
- 管理自定义开发的组件
- 一个简单的带Body的自定义Tag开发过程
- 一个简单的带Body的自定义Tag开发过程
- 随意拖动的picturebox服务器控件源码
- 一个简单的JMF开发的摄像头拍照程序源码
- Feature开发一(制作一个简单的自定义菜单)
- PictureBox 的简单操作 (C# WinForm)
- 自定义组件的简单使用—View
- 一个自定义LABEL组件的C#源代码
- 一个简单的自定义Collection
- 自定义一个简单的ScrollView
- 一个简单的自定义popupwindow
- 自定义一个简单的PopupWindow
- WSN术语
- 系统管理相关网址大全
- 数字运算技巧
- HDU2203——字符串
- 高效JavaScript 字符串替换函数的benchmark
- 一个简单的组件开发源码(自定义Picturebox)
- ORACLE初始化参数文件详细文档
- ids for this class must be manually assigned before calling save() hibernate
- CTime与CString相互转化的不错方法
- 计算整数位数
- 使用SqlBulkCopy类进行数据的批量插入
- 熟练的Java程序员应该掌握的技术
- 给字符数组不全赋值
- 手工完全卸载SQL SERVER2000数据库