'Es MUSS ein neues Benutzersteuerelement (Usercontrol)
'mit dem Namen:uscSymbols erzeugt werden
'und anschließend diesen Code hineinkopieren:
'© General Bison
'Da in VB.net die Linien etc von VB6 fehlen,
'ist hier der Ersatz ;)
'
'Info:
'Da das VisualStudio im Designer das Ziehen
'des Objektes kleiner 10Pixel nicht zulässt,
'MUSS die Höhe/Breite per Hand eingegeben werden,
'damit man eine Linie erhält.
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.ComponentModel
Public Class uscSymbols
Private Sub uscSymbols_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Enum FormArtEnum
<Description("Control wird als Rechteck dargestellt(als Linie nutzbar!)")> Rechteck
<Description("Stellt einen Kreis/Elipse dar")> Kreis
<Description("Das Control ist IMMMER Quadratisch")> Quadrat
<Description("links oben nach rechts unten")> LinksOben_RechtsUnten
<Description("rechts oben nach links unten")> RechtsOben_LinksUnten
End Enum
Private _FormArt As FormArtEnum = FormArtEnum.Rechteck
<Description("Die Darstellungsart")> _
Public Property FormArt() As FormArtEnum
Get
Return _FormArt
End Get
Set(ByVal value As FormArtEnum)
If _FormArt = FormArtEnum.Kreis AndAlso value <> _FormArt Then
CheckMyArt(value)
End If
_FormArt = value
If value > FormArtEnum.Quadrat Then
_RandSichtbar = True
End If
Me.Refresh()
End Set
End Property
Private _LockHeight As Integer
Private _SizeHeightLock As Boolean = False
<Description("Sperrt die aktuelle Höhe")> _
Public Property SizeHeightLock() As Boolean
Get
Return _SizeHeightLock
End Get
Set(ByVal value As Boolean)
_SizeHeightLock = value
_LockHeight = Me.Height
Me.Refresh()
End Set
End Property
Private _LockWidth As Integer
Private _SizeWidthLock As Boolean = False
<Description("Sperrt die aktuelle Breite")> _
Public Property SizeWidthLock() As Boolean
Get
Return _SizeWidthLock
End Get
Set(ByVal value As Boolean)
_SizeWidthLock = value
_LockWidth = Me.Width
Me.Refresh()
End Set
End Property
#Region "Rand"
Private _RandSichtbar As Boolean = False
<Description("Rand Darstellen")> _
Public Property RandSichtbar() As Boolean
Get
Return _RandSichtbar
End Get
Set(ByVal value As Boolean)
_RandSichtbar = value
Me.Refresh()
End Set
End Property
Private _RandDicke As Integer = 0
<Description("Randdicke in Pixeln. Kann nicht kleiner 0 sein!")> _
Public Property RandDicke() As Integer
Get
Return _RandDicke
End Get
Set(ByVal value As Integer)
If value >= 0 Then
_RandDicke = value
End If
Me.Refresh()
End Set
End Property
Private _RandFarbe As System.Drawing.Color = Color.White
<Description("Randfarbe")> _
Public Property RandFarbe() As System.Drawing.Color
Get
Return _RandFarbe
End Get
Set(ByVal value As System.Drawing.Color)
_RandFarbe = value
Me.Refresh()
End Set
End Property
#End Region
Private _Qualitaet As SmoothingMode = SmoothingMode.Default
<Description("Qualität des Objekts (zur zeit nur mit Effekt auf den Rand)")> _
Public Property Qualitaet() As SmoothingMode
Get
Return _Qualitaet
End Get
Set(ByVal value As SmoothingMode)
_Qualitaet = value
Me.Refresh()
End Set
End Property
Private Sub CheckMyArt(ByVal myart As FormArtEnum)
Select Case myart
Case FormArtEnum.Kreis
Dim Sb As New System.Drawing.Drawing2D.GraphicsPath
Sb.AddEllipse(2, 2, Me.Width - 5, Me.Height - 5)
Me.Region = New System.Drawing.Region(Sb)
Case Else
Dim Sb As New System.Drawing.Drawing2D.GraphicsPath
Dim r As New Rectangle(0, 0, Me.Width, Me.Height)
Sb.AddRectangle(r)
Me.Region = New System.Drawing.Region(Sb)
End Select
End Sub
Private Sub uscSymbols_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.SmoothingMode = _Qualitaet
Dim p As Pen
Dim r As Rectangle
CheckMyArt(_FormArt)
Select Case _FormArt
Case FormArtEnum.Kreis
If RandSichtbar = True Then
p = New Pen(_RandFarbe, _RandDicke)
r = New Rectangle(2, 2, Me.Width - 5, Me.Height - 5)
e.Graphics.DrawEllipse(p, r)
End If
Case FormArtEnum.Rechteck, FormArtEnum.Quadrat
If RandSichtbar = True Then
p = New Pen(_RandFarbe, _RandDicke)
r = New Rectangle(0, 0, Me.Width, Me.Height)
e.Graphics.DrawRectangle(p, r)
End If
Case FormArtEnum.LinksOben_RechtsUnten
p = New Pen(_RandFarbe, _RandDicke)
e.Graphics.DrawLine(p, 0, 0, Me.Width, Me.Height)
Case FormArtEnum.RechtsOben_LinksUnten
p = New Pen(_RandFarbe, _RandDicke)
e.Graphics.DrawLine(p, Me.Width, 0, 0, Me.Height)
End Select
End Sub
Private Sub uscSymbols_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
Select Case _FormArt
Case FormArtEnum.Quadrat
If Me.Width <> Me.Height Then
Me.Height = Me.Width
End If
End Select
If _SizeHeightLock = True Then
Me.Height = _LockHeight
End If
If _SizeWidthLock = True Then
Me.Width = _LockWidth
End If
End Sub
End Class