Tuesday, March 13, 2012

Fill a combo box with system fonts

Every system has many many fonts on it. Visual Basic allows us access to these fonts through its Screen object. Often getting font information can be very challenging, especially in the past using languages such as C++ or interacting directly through the Win32 API. Visual Basic makes this very easy. The source code below demonstrates this. It also demonstrates how you can use a for loop to loop through all the fonts. Lastly the source code demonstrates using a combo box control.

To use this source code sample simply create a new Visual Basic program, add a command button and a combo box to it. Double click on the command button to get into its click event handler method and add the code below.

        For I = 1 To Screen.FontCount - 1                Combo1.AddItem Screen.Fonts(I)

Obviously this is just the start to a program. You may for example want to allow the user to select a font and then apply that font to a text box or something else you have in your program.

Note: The source for this was found at DreamVB which is no longer online.


View the original article here

No comments:

Post a Comment