Hi
Hier gibts mal nen Code für die beliebte FontComboBox:
Ganz einfach zu bedienen:
Gruß
~blaze~
Hier gibts mal nen Code für die beliebte FontComboBox:
VB.NET-Quellcode
- Imports System.Windows.Forms
- Imports System.ComponentModel
- Public Class FontComboBox : Inherits ComboBox
- Private Sub FontComboBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
- Dim itm As Object = Me.Items(e.Index)
- Select Case e.State
- 'Wenn das Item Angewählt ist
- Case DrawItemState.Selected
- 'wird ein blauer Hintergrund gezeichnet
- e.Graphics.FillRectangle(Brushes.MidnightBlue, e.Bounds)
- If TypeOf itm Is FontFamily Then
- Try
- e.Graphics.DrawString(CType(itm, FontFamily).Name, New Font(CType(itm, FontFamily), 10), Brushes.White, e.Bounds.Location)
- Catch ex As Exception
- 'Kein Format vorhanden oder anderer Fehler
- e.Graphics.DrawString(CType(itm, FontFamily).Name, New Font("Arial", 9), Brushes.White, e.Bounds.Location)
- End Try
- ElseIf TypeOf itm Is Font Then
- e.Graphics.DrawString(CType(itm, Font).Name, itm, Brushes.White, e.Bounds.Location)
- Else
- e.Graphics.DrawString(itm.ToString, New Font("Arial", 9), Brushes.White, e.Bounds.Location)
- End If
- Case Else
- e.Graphics.FillRectangle(Brushes.White, e.Bounds)
- If TypeOf itm Is FontFamily Then
- Try
- e.Graphics.DrawString(CType(itm, FontFamily).Name, New Font(CType(itm, FontFamily), 10), Brushes.Black, e.Bounds.Location)
- Catch ex As Exception
- 'Kein Format vorhanden oder anderer Fehler
- e.Graphics.DrawString(CType(itm, FontFamily).Name, New Font("Arial", 9), Brushes.Black, e.Bounds.Location)
- End Try
- ElseIf TypeOf itm Is Font Then
- e.Graphics.DrawString(CType(itm, Font).Name, itm, Brushes.Black, e.Bounds.Location)
- Else
- e.Graphics.DrawString(itm.ToString, New Font("Arial", 9), Brushes.Black, e.Bounds.Location)
- End If
- End Select
- End Sub
- Private Sub FontComboBox_Format(ByVal sender As Object, ByVal e As System.Windows.Forms.ListControlConvertEventArgs) Handles Me.Format
- If TypeOf e.ListItem Is FontFamily Then
- 'Wenn das gewählte Item eine Font Family ist, soll der Name von ihr dargestellt werden.
- e.Value = CType(e.ListItem, FontFamily).Name
- End If
- End Sub
- 'Ausgeblender Modus
- <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
- Public Shadows Property DrawMode() As DrawMode
- Get
- Return MyBase.DrawMode
- End Get
- Set(ByVal value As DrawMode)
- MyBase.DrawMode = value
- End Set
- End Property
- ''' <summary>
- ''' Gibt an, ob die Schriftarten formattiert dargestellt werden sollen.
- ''' </summary>
- Public Property EnableFontFormatting() As Boolean
- Get
- Return MyBase.DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
- End Get
- Set(ByVal value As Boolean)
- If value = True Then
- MyBase.DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
- Else
- MyBase.DrawMode = Windows.Forms.DrawMode.Normal
- End If
- End Set
- End Property
- Public Sub New()
- '"Eigenhändiges" Zeichnen der Items aktivieren
- MyBase.DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
- End Sub
- End Class
Ganz einfach zu bedienen:
Gruß
~blaze~