Don’t hard-code font names and size

Unless you have good reason to do otherwise, you should always use standard fonts in your programs, because this ensures that your application will work on every Windows system.

If you want to use non-standard fonts, you should at least adopt the following guidelines:

  • Assign the font to form and controls through code in the Form_Load event procedure, not directly to the form or the control at design time. Most important, protect the assignment with an On Error statement, so that if the font doesn’t exist you can still use the default font.
  • Provide the end user with a method to customize the font name and size, for example by editing an INI file or the Registry. Obviously, editing the Registry is a risky operation, and it should be performed only by experienced users, so usually the INI file is better. Alternatively, provide a distinct utility that configures the program through an easy-to-use interface.
While we’re on this topic, please note that in general Visual Basic doesn’t raise an error when you assign an unsupported size of a font, but silently uses the closest valid font size that is less than the requested size. Therefore, the only way to test if a given font size actually exists is to check that the assignment was successful. Here’s a routine that lets you assign a font size to any object, and returns True if the specified font size is supperted:

Function SetFontSize(obj As Object, FontSize As Integer) As Boolean    On Error Resume Next    obj.Font.Size = FontSize    SetFontSize = (obj.Font.Size = FontSize)End Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job