vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Brandneu! sevEingabe v3.0 - Das Eingabecontrol der Superlative!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
Re: Combobox Fontauswahl mit angepasst formatierten DropDown-Einträgen 
Autor: Manfred X
Datum: 05.02.23 10:38

Hallo!

Achte bei diesem Import darauf, welcher Combobox-Klase Du verwendest.

Imports System.Windows.Forms.VisualStyles.VisualStyleElement
 
Public Class frmFontCombo
 
    'Namespace genau angeben
    Dim WithEvents cmb As New Windows.Forms.ComboBox With
        {.Parent = Me, .Width = 150, .DropDownStyle = _
          ComboBoxStyle.DropDownList}
 
 
 
    Private Sub frmFontCombo_Load(sender As Object, e As EventArgs) Handles _
      MyBase.Load
        FillCombobox()
    End Sub
 
 
    Private Sub FillCombobox()
 
        ' alle verfügbaren Schriften auflisten
        With cmb.Items
            For Each oFont As FontFamily In Font.FontFamily.Families
                .Add(oFont)
            Next
        End With
 
        ' Wir möchten uns um die Ausgabe der 
        ' Listen-Einträge selbst kümmern
        cmb.DrawMode = DrawMode.OwnerDrawFixed
    End Sub
 
 
    Private Sub cmb_DrawItem(ByVal sender As Object,
         ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cmb.DrawItem
 
        Dim sitem As String, ofont As Drawing.Font
        If e.Index < 0 Then Exit Sub
 
        With cmb
            ' ComboBox-Eintrag (Schriftname)
            sitem = .Items(e.Index).Name
 
            ' Neues Schrift-Objekt erzeugen und verfügbare Styles 
            ' berücksichtigen
            Dim oFamily As FontFamily = .Items(e.Index)
            If oFamily.IsStyleAvailable(FontStyle.Regular) Then
                ofont = New Font(sItem, .Font.Size, FontStyle.Regular)
            ElseIf oFamily.IsStyleAvailable(FontStyle.Italic) Then
                ofont = New Font(sItem, .Font.Size, FontStyle.Italic)
            ElseIf oFamily.IsStyleAvailable(FontStyle.Bold) Then
                ofont = New Font(sItem, .Font.Size, FontStyle.Bold)
            ElseIf oFamily.IsStyleAvailable(FontStyle.Underline) Then
                ofont = New Font(sItem, .Font.Size, FontStyle.Underline)
            Else
                ofont = New Font(sItem, .Font.Size, FontStyle.Strikeout)
            End If
        End With
 
        ' Brush für Textfarbe
        Using oBrush As Brush = New SolidBrush(e.ForeColor)
 
            ' Hintergrund
            e.DrawBackground()
 
            ' Text (Schriftname) ausgeben
            e.Graphics.DrawString(sitem, ofont, oBrush, e.Bounds.X, e.Bounds.Y)
        End Using
 
    End Sub
 
End Class
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Combobox Fontauswahl mit angepasst formatierten DropDown-Ein...475Dideldum04.02.23 23:19
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...336Manfred X05.02.23 10:38
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...290Dideldum05.02.23 23:08
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...292Kuno6006.02.23 01:32
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...227Manfred X06.02.23 08:40
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...185Dideldum11.02.23 18:59
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...188Dideldum05.03.23 18:19
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...160Dideldum06.03.23 16:27
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...111Dideldum07.03.23 18:27
Re: Combobox Fontauswahl mit angepasst formatierten DropDown...112Dideldum09.03.23 21:46

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel