vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Mails senden, abrufen und decodieren - ganz easy ;-)  
 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: Kuno60
Datum: 06.02.23 01:32

Hallo Dideldum!

Die ToolStripComboBox ist eine gehostete ComboBox für ToolStrips (Symbolleisten, Kontextmenüs). Sie besitzt eine Eigenschaft "ComboBox". Damit kann auf die interne ComboBox zugegriffen werden. Somit steht auch "DrawMode" zur Verfügung.

Dieses Beispiel benötigt eine "Form1" mit einem "ToolStrip" und auf diesem eine "ToolStripComboBox1".
Public Class Form1
 
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    With ToolStripComboBox1
      For Each f In FontFamily.Families
        .Items.Add(f)
      Next
      .ComboBox.DrawMode = DrawMode.OwnerDrawFixed
      .ComboBox.DropDownStyle = ComboBoxStyle.DropDownList
      AddHandler .ComboBox.DrawItem, AddressOf ToolStripComboBox1_DrawItem
    End With
  End Sub
 
  ' Vertikale Zentrierung
  Private Shared ReadOnly SF As New StringFormat With {.LineAlignment = _
    StringAlignment.Center}
 
  ' Items zeichnen
  Private Sub ToolStripComboBox1_DrawItem(sender As Object, e As _
    DrawItemEventArgs)
    If e.Index < 0 Then Return
    With ToolStripComboBox1
 
      Dim ff As FontFamily = DirectCast(.Items(e.Index), FontFamily)
      Dim fs As Single = .Font.Size
 
      Dim oFont As Font
      If ff.IsStyleAvailable(FontStyle.Regular) Then
        oFont = New Font(ff, fs, FontStyle.Regular)
      ElseIf ff.IsStyleAvailable(FontStyle.Italic) Then
        oFont = New Font(ff, fs, FontStyle.Italic)
      ElseIf ff.IsStyleAvailable(FontStyle.Bold) Then
        oFont = New Font(ff, fs, FontStyle.Bold)
      ElseIf ff.IsStyleAvailable(FontStyle.Underline) Then
        oFont = New Font(ff, fs, FontStyle.Underline)
      Else
        oFont = New Font(ff, fs, FontStyle.Strikeout)
      End If
 
      e.DrawBackground()
      Using oBrush As New SolidBrush(e.ForeColor)
        e.Graphics.DrawString(ff.Name, oFont, oBrush, e.Bounds, SF)
      End Using
    End With
  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...293Kuno6006.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