Hallööle..
Ich arbeite seit 2-3 tagen an ein paar kleinen Controls..
(Das standarddesign ist blau, aber man kann alle farben ändern - per propertys)
#Edit
Jetzt mit Option Strict On!
Button.vb
Spoiler anzeigen
InfoButton.vb
Spoiler anzeigen
ProgressBar.vb
Spoiler anzeigen
Part 2 kommt demnächst!:)
Ich arbeite seit 2-3 tagen an ein paar kleinen Controls..
(Das standarddesign ist blau, aber man kann alle farben ändern - per propertys)
#Edit
Jetzt mit Option Strict On!
Button.vb
VB.NET-Quellcode
- Option Strict On
- Imports System.ComponentModel
- Public Enum MouseState As Byte
- None
- Hover
- Pressed
- End Enum
- Public Class Button
- Inherits System.Windows.Forms.Button
- Private _Color1 As System.Drawing.Color
- <Category("Button")> _
- Public Property Color1 As System.Drawing.Color
- Get
- Return Me._Color1
- End Get
- Set(ByVal value As System.Drawing.Color)
- Me._Color1 = value
- Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
- Me.Invalidate()
- End Set
- End Property
- Private _Color2 As System.Drawing.Color
- <Category("Button")> _
- Public Property Color2 As System.Drawing.Color
- Get
- Return Me._Color2
- End Get
- Set(ByVal value As System.Drawing.Color)
- Me._Color2 = value
- Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
- Me.Invalidate()
- End Set
- End Property
- Private _Color1H As System.Drawing.Color
- Private _Color2H As System.Drawing.Color
- Private _MouseState As MouseState
- Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
- MyBase.OnMouseEnter(e)
- Me._MouseState = MouseState.Hover
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
- MyBase.OnMouseEnter(e)
- Me._MouseState = MouseState.None
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnMouseDown(ByVal mevent As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseDown(mevent)
- Me._MouseState = MouseState.Pressed
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnMouseUp(ByVal mevent As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseUp(mevent)
- Me._MouseState = MouseState.Hover
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
- MyBase.OnPaint(e)
- e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
- Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 8)
- If Me._MouseState = MouseState.None Then
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1, Me._Color2), globalRect)
- ElseIf Me._MouseState = MouseState.Hover Then
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1H, Me._Color2H), globalRect)
- ElseIf Me._MouseState = MouseState.Pressed Then
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color2H, Me._Color1H), globalRect)
- End If
- e.Graphics.FillPath(New System.Drawing.Drawing2D.HatchBrush(Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal, System.Drawing.Color.FromArgb(&H0), System.Drawing.Color.FromArgb(&HF000000)), globalRect)
- Dim TextSize As Drawing.SizeF = e.Graphics.MeasureString(Me.Text, Me.Font, Me.Width)
- e.Graphics.DrawString(Me.Text, Me.Font, New Drawing.SolidBrush(Me.ForeColor), New Drawing.Point(CInt(Me.Width / 2) - CInt(TextSize.Width / 2), CInt(Me.Height / 2) - CInt(TextSize.Height / 2)))
- e.Graphics.DrawPath(Drawing.Pens.DimGray, globalRect)
- End Sub
- Sub New()
- Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
- Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
- Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
- Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
- Me.Size = New System.Drawing.Size(100, 25)
- Me._MouseState = MouseState.None
- Me.Cursor = Windows.Forms.Cursors.Hand
- End Sub
- End Class
InfoButton.vb
VB.NET-Quellcode
- Option Strict On
- Imports System.ComponentModel
- Public Class InfoButton
- Inherits System.Windows.Forms.Button
- Private _Color1 As System.Drawing.Color
- <Category("Button")> _
- Public Property Color1 As System.Drawing.Color
- Get
- Return Me._Color1
- End Get
- Set(ByVal value As System.Drawing.Color)
- Me._Color1 = value
- Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
- Me.Invalidate()
- End Set
- End Property
- Private _Color2 As System.Drawing.Color
- <Category("Button")> _
- Public Property Color2 As System.Drawing.Color
- Get
- Return Me._Color2
- End Get
- Set(ByVal value As System.Drawing.Color)
- Me._Color2 = value
- Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
- Me.Invalidate()
- End Set
- End Property
- Private _TextInfo As String
- <Category("Darstellung")> _
- Public Property TextInfo As String
- Get
- Return Me._TextInfo
- End Get
- Set(value As String)
- Me._TextInfo = value
- Me.Invalidate()
- End Set
- End Property
- Private _InfoTextFont As Drawing.Font
- <Category("Button")> _
- Public Property InfoTextFont As Drawing.Font
- Get
- Return Me._InfoTextFont
- End Get
- Set(value As Drawing.Font)
- Me._InfoTextFont = value
- Me.Invalidate()
- End Set
- End Property
- Private _InfoTextColor As Drawing.Color
- <Category("Button")> _
- Public Property InfoTextColor As Drawing.Color
- Get
- Return Me._InfoTextColor
- End Get
- Set(value As Drawing.Color)
- Me._InfoTextColor = value
- Me.Invalidate()
- End Set
- End Property
- Private _Color1H As System.Drawing.Color
- Private _Color2H As System.Drawing.Color
- Private _MouseState As MouseState
- Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
- MyBase.OnMouseEnter(e)
- Me._MouseState = MouseState.Hover
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
- MyBase.OnMouseEnter(e)
- Me._MouseState = MouseState.None
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnMouseDown(ByVal mevent As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseDown(mevent)
- Me._MouseState = MouseState.Pressed
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnMouseUp(ByVal mevent As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseUp(mevent)
- Me._MouseState = MouseState.Hover
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
- MyBase.OnPaint(e)
- e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
- Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 8)
- If Me._MouseState = MouseState.None Then
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1, Me._Color2), globalRect)
- ElseIf Me._MouseState = MouseState.Hover Then
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1H, Me._Color2H), globalRect)
- ElseIf Me._MouseState = MouseState.Pressed Then
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color2H, Me._Color1H), globalRect)
- End If
- e.Graphics.FillPath(New System.Drawing.Drawing2D.HatchBrush(Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal, System.Drawing.Color.FromArgb(&H0), System.Drawing.Color.FromArgb(&HF000000)), globalRect)
- Dim TextSize As Drawing.SizeF = e.Graphics.MeasureString(Me.Text, Me.Font, Me.Width)
- e.Graphics.DrawString(Me.Text, Me.Font, New Drawing.SolidBrush(Me.ForeColor), New Drawing.Point(5, 5))
- e.Graphics.DrawString(Me._TextInfo, Me._InfoTextFont, New Drawing.SolidBrush(Me._InfoTextColor), New Drawing.Point(10, CInt(TextSize.Height + 5)))
- e.Graphics.DrawPath(Drawing.Pens.DimGray, globalRect)
- End Sub
- Sub New()
- Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
- Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
- Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
- Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
- Me.Size = New System.Drawing.Size(125, 40)
- Me._MouseState = MouseState.None
- Me.Cursor = Windows.Forms.Cursors.Hand
- Me._InfoTextColor = Drawing.Color.FromArgb(25, 25, 25)
- Me._TextInfo = "Information..."
- Me._InfoTextFont = New Drawing.Font(Me.Font.FontFamily, 7)
- End Sub
- End Class
ProgressBar.vb
VB.NET-Quellcode
- Option Strict On
- Imports System.ComponentModel
- Public Class ProgressBar
- Inherits System.Windows.Forms.Control
- Private _Color1 As System.Drawing.Color
- <Category("Progressbar")> _
- Public Property Color1 As System.Drawing.Color
- Get
- Return Me._Color1
- End Get
- Set(ByVal value As System.Drawing.Color)
- Me._Color1 = value
- Me.Invalidate()
- End Set
- End Property
- Private _Color2 As System.Drawing.Color
- <Category("Progressbar")> _
- Public Property Color2 As System.Drawing.Color
- Get
- Return Me._Color2
- End Get
- Set(ByVal value As System.Drawing.Color)
- Me._Color2 = value
- Me.Invalidate()
- End Set
- End Property
- Private _Minimum As UInteger
- <Category("Progressbar")> _
- Public Property Minimum As UInteger
- Get
- Return Me._Minimum
- End Get
- Set(ByVal value As UInteger)
- If value > Me._Maximum Then Throw New Exception("Minimum value cant be greater than maximum value")
- Me._Minimum = value
- End Set
- End Property
- Private _Maximum As UInteger
- <Category("Progressbar")> _
- Public Property Maximum As UInteger
- Get
- Return Me._Maximum
- End Get
- Set(ByVal value As UInteger)
- If value < Me._Minimum Then Throw New Exception("Maximum value cant be less than minimum value")
- Me._Maximum = value
- End Set
- End Property
- Private _Value As UInteger
- <Category("Progressbar")> _
- Public Property Value As UInteger
- Get
- Return Me._Value
- End Get
- Set(ByVal value As UInteger)
- If value < Me._Minimum OrElse value > Me._Maximum Then Throw New Exception("Value must be beteween minimum and maximum value")
- Me._Value = value
- End Set
- End Property
- Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
- MyBase.OnPaint(e)
- e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
- Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 8)
- Dim valueRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, (CInt((Me.Width) * Me._Value / Me._Maximum)), Me.Height - 1), 8)
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Drawing.Color.FromArgb(255, 189, 189, 189), Drawing.Color.FromArgb(255, 219, 219, 219)), globalRect)
- e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1, Me._Color2), valueRect)
- e.Graphics.FillPath(New System.Drawing.Drawing2D.HatchBrush(Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal, System.Drawing.Color.FromArgb(&H0), System.Drawing.Color.FromArgb(&HF000000)), valueRect)
- e.Graphics.DrawPath(Drawing.Pens.LightSlateGray, valueRect)
- e.Graphics.DrawPath(Drawing.Pens.DimGray, globalRect)
- End Sub
- Sub New()
- Me._Minimum = 0
- Me._Maximum = 100
- Me._Value = 50
- Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
- Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
- Me.Size = New System.Drawing.Size(200, 10)
- Me.Text = ""
- End Sub
- End Class
Part 2 kommt demnächst!:)
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „BeefyX“ ()