Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2016. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Fonts ComboBox Demo
- '
- ' Author: Joseph L. Bolen
- ' Date Created: 26 AUG 2016
- '
- ' Description: Show installed fonts in combobox.
- '
- ' Documentation is at:
- ' App's screen image is at: http://imgur.com/tYymDwQ
- ' App's Visual Basic .NET code is at http://pastebin.com/q2K1VGsy
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '-------------------------------------------------------------------------------------------
- Public Class MainForm
- Private Sub MainForm_Load(sender As Object, e As EventArgs) _
- Handles MyBase.Load
- ' Get the installed fonts and load the combo box.
- Dim installedFonts As New System.Drawing.Text.InstalledFontCollection
- With FontsComboBox
- ' Allow user to draw control.
- .DrawMode = DrawMode.OwnerDrawFixed
- ' If you wish to control MaxDropDownItems, set IntegralHeight property to false.
- .IntegralHeight = False
- .MaxDropDownItems = 8
- .DataSource = (From fontFamiles In installedFonts.Families Select fontFamiles.Name).ToList
- .SelectedItem = FontExampleLabel.Font.Name
- End With
- AddHandler FontsComboBox.SelectedIndexChanged, AddressOf FontsComboBox_SelectedIndexChanged
- End Sub
- ' Change the font of label when FontsComboBox changes value.
- Private Sub FontsComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
- If FontsComboBox.SelectedIndex <> -1 Then
- FontExampleLabel.Font =
- New Font(FontsComboBox.SelectedItem.ToString, FontExampleLabel.Font.Size)
- End If
- End Sub
- ' Draw each item in the control's collection with the item's font.
- Private Sub FontsComboBox_DrawItem(sender As Object, e As DrawItemEventArgs) _
- Handles FontsComboBox.DrawItem
- Dim myComboBox As ComboBox = CType(sender, ComboBox)
- Dim myFont As New Font(CType(myComboBox.Items(e.Index), String), myComboBox.Font.Size)
- ' Draw the background of the ComboBox control for each item.
- e.DrawBackground()
- ' Define the default color of the brush.
- Using mybrush As New SolidBrush(e.ForeColor)
- ' Draw the current item text based on the current font and brush settings.
- e.Graphics.DrawString(myFont.Name, myFont, mybrush, e.Bounds, StringFormat.GenericDefault)
- End Using
- ' If the control has focus, draw a focus rectangle around the selected item.
- e.DrawFocusRectangle()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment