This is the first time I write in Microsoft Forums so I like to share some of my 'home made' controls Check out this control, it semulates LED, it's useful in desiging hardware automation programs, PCB semulators, .. etc.
Just create a new 'User Control' and replace all code inside it with the following:
Imports
System.ComponentModel.EditorAttributePublic
Class LED Inherits System.Windows.Forms.UserControl#
Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer.InitializeComponent()
'Add any initialization after the InitializeComponent() call End Sub 'UserControl overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Thencomponents.Dispose()
End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor.<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent() ' 'LED ' Me.Name = "LED" Me.Size = New System.Drawing.Size(136, 136) End Sub#
End Region Private Sub LED_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub LED_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Try Dim gx As Graphics = e.Graphics Dim rx As Rectangle = e.ClipRectangle Dim BackBrush As Brush = New SolidBrush(Me.BackColor) Dim LEDEdge As New Drawing.Drawing2D.GraphicsPath(Drawing2D.FillMode.Winding) Dim SC As Color() = {Me.ForeColor} If CircleShape ThenLEDEdge.AddEllipse(rx)
ElseLEDEdge.AddRectangle(rx)
End If Dim CenterPoint As Point = New Point(rx.Width / 2, rx.Height / 2) Dim LEDBrush As Drawing2D.PathGradientBrush = New Drawing2D.PathGradientBrush(LEDEdge) Dim TextBrush As Brush = New SolidBrush(Color.Black) If LEDON ThenLEDBrush.CenterColor = SetHue(
Me.ForeColor, 200) ElseLEDBrush.CenterColor = SetHue(
Me.ForeColor, -20) End IfLEDBrush.CenterPoint =
New Drawing.PointF(CenterPoint.X, CenterPoint.Y)LEDBrush.SurroundColors = SC
gx.FillRectangle(BackBrush, rx)
gx.FillPath(LEDBrush, LEDEdge)
Dim LeftText As Integer = Me.Width / 2 Dim TopText As Integer = Me.Height / 2 If Me.Text <> "" Then Dim BF As Font = New Font(Me.Font.FontFamily, Me.Font.Size)LeftText -= gx.MeasureString(
Me.Text, BF).Width / 2TopText -= gx.MeasureString(
Me.Text, BF).Height / 2gx.DrawString(
Me.Text, BF, New SolidBrush(Color.Black), LeftText + 1, TopText + 1)LeftText =
Me.Width / 2TopText =
Me.Height / 2LeftText -= gx.MeasureString(
Me.Text, Me.Font).Width / 2TopText -= gx.MeasureString(
Me.Text, Me.Font).Height / 2gx.DrawString(
Me.Text, Me.Font, New SolidBrush(Color.White), LeftText, TopText) End If Catch ex As ExceptionDebug.Write(ex.ToString)
End Try End Sub Private Sub LED_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize Me.Refresh() End Sub Private Sub LED_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged Me.Refresh() End Sub Private Sub LED_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged Me.Refresh() End Sub Private _LEDON As Boolean Public Property LEDON() As Boolean GetLEDON = _LEDON
'me.Refresh End Get Set(ByVal Value As Boolean)_LEDON = Value
Me.Refresh() End Set End Property Private _CircleShape As Boolean = True Public Property CircleShape() As Boolean GetCircleShape = _CircleShape
End Get Set(ByVal Value As Boolean)_CircleShape = Value
Me.Refresh() End Set End Property Private Function SetHue(ByVal valColor As Drawing.Color, ByVal valHue As Integer) As Color Dim TempColor As Color Dim TempR As Integer Dim TempG As Integer Dim TempB As IntegerTempR = valColor.R + valHue
If TempR > 255 ThenTempR = 255
ElseIf TempR < 0 ThenTempR = 0
End IfTempG = valColor.G + valHue
If TempG > 255 ThenTempG = 255
ElseIf TempG < 0 ThenTempG = 0
End IfTempB = valColor.B + valHue
If TempB > 255 ThenTempB = 255
ElseIf TempB < 0 ThenTempB = 0
End IfTempColor = Color.FromArgb(TempR, TempG, TempB)
Return TempColor End Function Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs) Me.Refresh() End SubEnd
ClassEnjoy :)
Abdullah Al-Rasheed

Control to semulate LED