#Region "Event-Handler"
Private Sub PenOptionsDialog_Load(sender As System.Object, _
e As System.EventArgs) Handles MyBase.Load
'Combos einrichten
For Each ctl As Control In Me.Controls
If TypeOf ctl Is ComboBox Then
Dim cbo As ComboBox = DirectCast(ctl, ComboBox)
With cbo
.DrawMode = DrawMode.OwnerDrawFixed
.DropDownStyle = ComboBoxStyle.DropDownList
.Width = 100 : .Left = 70
End With
End If
Next
With cboPenWidth
.Items.AddRange({"1", "2", "4", "8", "12"})
.Font = New Font("Courier New", 10)
.SelectedIndex = 0
If Not _pen Is Nothing Then
Dim i% = .Items.IndexOf(_pen.Width.ToString)
If Not i = -1 Then .SelectedIndex = i
End If
End With
With cboPenStyle
.Items.AddRange([Enum].GetNames(GetType(DashStyle)))
.Items.RemoveAt(5)
.SelectedIndex = 0
If _pen IsNot Nothing Then
.SelectedIndex = _pen.DashStyle
End If
End With
With cboPenAlignment
.Items.AddRange([Enum].GetNames(GetType(PenAlignment)))
.SelectedIndex = 0
If _pen IsNot Nothing Then
.SelectedIndex = _pen.Alignment
End If
End With
With cboPenColor
.Visible = .Items.Count > 0
If _pen IsNot Nothing Then
For i As Integer = 0 To .Items.Count - 1
If .Items(i).ToString = _pen.Color.Name Then
.SelectedIndex = i : Exit For
End If
Next i
End If
End With
'Dialog-Eigenschaften
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
Me.MinimizeBox = False
Me.MaximizeBox = False
Me.Size = New Size(180, 230)
If Me.Owner IsNot Nothing Then
Me.StartPosition = FormStartPosition.Manual
Dim loc As Point = Me.Owner.Location
loc.Offset(30, 30)
Me.Location = loc
Else
Me.StartPosition = FormStartPosition.WindowsDefaultLocation
End If
End Sub
Private Sub cboLineColor_DrawItem(sender As Object, _
e As System.Windows.Forms.DrawItemEventArgs) Handles _
cboPenColor.DrawItem
Dim col As Drawing.Color = Color.FromName(cboPenColor.Items( _
e.Index).ToString)
e.DrawBackground()
Using br As New SolidBrush(col)
With e.Bounds
Dim colrect As New Rectangle(.X + 2, .Y + 2, .Width - 4, _
.Height - 4)
e.Graphics.FillRectangle(br, colrect)
e.Graphics.DrawRectangle _
(New Drawing.Pen(GetForecolor(e.State), 2), colrect)
End With
End Using
End Sub
Private Sub cboLineWidth_DrawItem(sender As Object, _
e As System.Windows.Forms.DrawItemEventArgs) Handles cboPenWidth.DrawItem
If e.Index = -1 Then Exit Sub
e.DrawBackground()
'Position der Linie im Item
Dim startpoint As New Point _
(e.Bounds.Left + 4, e.Bounds.Top + cboPenWidth.ItemHeight \ 2)
Dim endpoint As New Point _
(startpoint.X + (e.Bounds.Width - 8), startpoint.Y)
Using pn As New Pen(GetForecolor(e.State), _
CInt(cboPenWidth.Items(e.Index).ToString))
Dim ypos% = cboPenStyle.ItemHeight \ 2
With e.Bounds
e.Graphics.DrawLine(pn, startpoint, endpoint)
End With
End Using
End Sub |