[2005] Basic Line Control

For Lack of a better tool, I whipped this one together. I know I did not put all of the XML descriptions and Component details on it yet...That is all just fluff. Nice, easy control.

Option Explicit On
Option Strict On

Imports System.ComponentModel

Public Class LineControl

#Region " Properties "

Private _X1 As Single = 0
Private _Y1 As Single = 0
Private _Length As Single = 200
Private _DashStyle As Drawing2D.DashStyle = Drawing2D.DashStyle.Solid
Private _DashCap As Drawing2D.DashCap = Drawing2D.DashCap.Flat
Private _LineColor As System.Drawing.Color = Color.Black
Private _LineWidth As Integer = 4

Private LinePen As Pen

Public Property X() As Single
Get
Return _X1
End Get
Set(ByVal value As Single)
_X1 = value
End Set
End Property

Public Property Y() As Single
Get
Return _Y1
End Get
Set(ByVal value As Single)
_Y1 = value
End Set
End Property

Public Property Length() As Single
Get
Return _Length
End Get
Set(ByVal value As Single)
_Length = value
MyBase.Width = CInt(value)
MyBase.Invalidate()
End Set
End Property

Public Property DashStyle() As Drawing2D.DashStyle
Get
Return _DashStyle
End Get
Set(ByVal value As Drawing2D.DashStyle)
_DashStyle = value
MyBase.Invalidate()
End Set
End Property

Public Property DashCap() As Drawing2D.DashCap
Get
Return _DashCap
End Get
Set(ByVal value As Drawing2D.DashCap)
_DashCap = value
MyBase.Invalidate()
End Set
End Property

Public Property LineColor() As Color
Get
Return _LineColor
End Get
Set(ByVal value As Color)
_LineColor = value
MyBase.Invalidate()
End Set
End Property

Public Property LineWidth() As Integer
Get
Return _LineWidth
End Get
Set(ByVal value As Integer)
_LineWidth = value
MyBase.Height = value
MyBase.Invalidate()
End Set
End Property

<Browsable(False)> _
Public Overrides Property ForeColor() As System.Drawing.Color
Get
Return MyBase.ForeColor
End Get
Set(ByVal value As System.Drawing.Color)
MyBase.ForeColor = value
End Set
End Property

<Browsable(False)> _
Public Overrides Property Font() As System.Drawing.Font
Get
Return MyBase.Font
End Get
Set(ByVal value As System.Drawing.Font)
MyBase.Font = value
End Set
End Property

<Browsable(False)> _
Public Overrides Property BackgroundImage() As System.Drawing.Image
Get
Return MyBase.BackgroundImage
End Get
Set(ByVal value As System.Drawing.Image)
MyBase.BackgroundImage = value
End Set
End Property

<Browsable(False)> _
Public Overrides Property BackgroundImageLayout() As System.Windows.Forms.ImageLayout
Get
Return MyBase.BackgroundImageLayout
End Get
Set(ByVal value As System.Windows.Forms.ImageLayout)
MyBase.BackgroundImageLayout = value
End Set
End Property

<Browsable(False)> _
Public Overrides ReadOnly Property Focused() As Boolean
Get
Return MyBase.Focused
End Get
End Property

<Browsable(False)> _
Public Overrides Property RightToLeft() As System.Windows.Forms.RightToLeft
Get
Return MyBase.RightToLeft
End Get
Set(ByVal value As System.Windows.Forms.RightToLeft)
MyBase.RightToLeft = value
End Set
End Property

#End Region

Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
MyBase.Width = CInt(Length)
MyBase.Height = LineWidth
End Sub

Private Sub LineControl_Paint(ByVal sender As Object, ByVal e As Windows.Forms.PaintEventArgs) Handles Me.Paint
LinePen = New Pen(LineColor, LineWidth)
With LinePen
.DashCap = DashCap
.DashStyle = DashStyle
End With

e.Graphics.DrawLine(LinePen, X, Y, X + Length, Y)
End Sub

Private Sub LineControl_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Length = MyBase.Width
MyBase.Height = CInt(LineWidth)
End Sub

End Class

As usual, any suggestions, updates, etc are more than welcome. No criticism, my fragile ego cannot take it!!! ;)

D
[5622 byte] By [dminder] at [2007-12-5 11:46:22]