Ein komplettes Control (es fehlen noch ein paar Attributes und so)
Imports System.ComponentModel
Public Class LineControl
Inherits Control
Implements ISupportInitialize
Private _ps As Point = New Point(0, 0)
Private _pe As Point = New Point(100, 100)
Private _color As Color = Color.Black
Private _width As Integer = 1
Private _pen As Pen
Private _init As Boolean
Public Sub New()
MyBase.New()
_pen = New Pen(LineColor, LineWidth)
Me.Dock = DockStyle.Fill
End Sub
Public Sub New(ByVal ps As Point, ByVal pe As Point, ByVal lineColor As _
Color, ByVal lineWidth As Integer)
MyBase.New()
_ps = ps
_pe = pe
_color = lineColor
_width = lineWidth
_pen = New Pen(lineColor, lineWidth)
Me.Dock = DockStyle.Fill
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If _pen IsNot Nothing Then
_pen.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
Public Property StartPoint() As Point
Get
Return _ps
End Get
Set(ByVal value As Point)
_ps = value
Me.Refresh()
End Set
End Property
Public Property EndPoint() As Point
Get
Return _pe
End Get
Set(ByVal value As Point)
_pe = value
Me.Refresh()
End Set
End Property
Public Property LineColor() As Color
Get
Return _color
End Get
Set(ByVal value As Color)
_color = value
If _init Then Return
If _pen IsNot Nothing Then
_pen.Dispose()
End If
_pen = New Pen(value, _width)
Me.Refresh()
End Set
End Property
Public Property LineWidth() As Integer
Get
Return _width
End Get
Set(ByVal value As Integer)
_width = value
If _init Then Return
If _pen IsNot Nothing Then
_pen.Dispose()
End If
_pen = New Pen(_color, value)
Me.Refresh()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As _
System.Windows.Forms.PaintEventArgs)
If _pen Is Nothing Then Return
e.Graphics.DrawLine(_pen, _ps, _pe)
End Sub
Protected Overrides ReadOnly Property CreateParams() As _
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaintBackground(ByVal pevent As _
System.Windows.Forms.PaintEventArgs)
' Don't draw background!
End Sub
Public Sub BeginInit() Implements _
System.ComponentModel.ISupportInitialize.BeginInit
_init = True
End Sub
Public Sub EndInit() Implements _
System.ComponentModel.ISupportInitialize.EndInit
_init = False
If _pen IsNot Nothing Then
_pen.Dispose()
End If
_pen = New Pen(_color, _width)
End Sub
End Class ________
Alle Angaben ohne Gewähr. Keine Haftung für Vorschläge, Tipps oder sonstige Hilfe, falls es schiefgeht, nur Zeit verschwendet oder man sonst nicht zufrieden ist |