fonts in programs

A

andreas

How can I choose some fonts in programs so that they are always avalable for
the program at other computers, can I put them in some resources?
Thanks for any response
 
A

andrews

Maybe more specific
I can choose in the properties for many controls font.
When the program run on a other computer where has not this font what
happens?
Can I put the font into the code in some of another way so that the font
is always avalable for the program?
Thanks for any response.
 
K

kimiraikkonen

Maybe more specific
I can choose in the properties for many controls font.
When the program run on a other computer where has not this font what
happens?
Can I put the font into the code in some of another way so that the font
is always avalable for the program?
Thanks for any response.

Usually, if the specified font cannot be found on target machine, your
application is supposed to run with a proper font that your system
supports, however you can check the intended font file's existence
using System.IO.File.Exists preferably on form's load event:

'-----Begin-------------
' It's unlikely that a Windows client doesn't have Arial
' But check it out for the scenario
If System.IO.File.Exists _
("c:\Windows\Fonts\arial.ttf")=True Then
MsgBox("Arial is found")

Else
'Implement new font instance
'Eg: Verdana, sized 20
Dim myfont As New Font("Verdana", 20)

'Associate new font with control's font
'Eg: Button's new font is verdana
Button1.Font = myfont
End If
'-------End----------

Hope this helps,

Onur Güzel
 
G

Gillard

checking a hard path is never a good idee "c:\Windows\Fonts\arial.ttf"

better find Windows directory first and then check for the file
some people did not install in c:\windows
 
J

James Hahn

Checking a file is not an effective way to find out what fonts are installed
in a aystem. Use the InstalledFontCollection class to enumerate the
available fonts.

Maybe more specific
I can choose in the properties for many controls font.
When the program run on a other computer where has not this font what
happens?
Can I put the font into the code in some of another way so that the font
is always avalable for the program?
Thanks for any response.

Usually, if the specified font cannot be found on target machine, your
application is supposed to run with a proper font that your system
supports, however you can check the intended font file's existence
using System.IO.File.Exists preferably on form's load event:

'-----Begin-------------
' It's unlikely that a Windows client doesn't have Arial
' But check it out for the scenario
If System.IO.File.Exists _
("c:\Windows\Fonts\arial.ttf")=True Then
MsgBox("Arial is found")

Else
'Implement new font instance
'Eg: Verdana, sized 20
Dim myfont As New Font("Verdana", 20)

'Associate new font with control's font
'Eg: Button's new font is verdana
Button1.Font = myfont
End If
'-------End----------

Hope this helps,

Onur Güzel
 
K

kimiraikkonen

checking a hard path is never a good idee "c:\Windows\Fonts\arial.ttf"

better find Windows directory first and then check for the file
some people did not install in c:\windows

Sure, but also your idea is based on file checking which is quite
effective in my idea, though user can install Windows to another
directory although c:\Windows is quite common, however you can use
that for determining Windows directory:

Dim WinDir As String = _
Environment.GetEnvironmentVariable("windir")
Dim fontsFolder As String = WinDir & "\Fonts"

....which solves default Windows Directory also combining Font folder.

Thanks,

Onur Güzel
 
A

Andrew Morton

andreas said:
How can I choose some fonts in programs so that they are always
avalable for the program at other computers, can I put them in some
resources?

Fonts are usually copyrighted, so: no.

Other posters have mentioned looking in the fonts folder. You should be able
to get the location of the fonts folder through this information from
ShlObj.h from the Windows SDK:

<snip>
//-------------------------------------------------------------------------
//
// SHGetSpecialFolderLocation
//
// Caller should use SHGetMalloc to obtain an allocator that can free the
pidl
//
//
//-------------------------------------------------------------------------
//
// registry entries for special paths are kept in :
#define REGSTR_PATH_SPECIAL_FOLDERS REGSTR_PATH_EXPLORER TEXT("\\Shell
Folders")


#define CSIDL_DESKTOP 0x0000 // <desktop>
#define CSIDL_INTERNET 0x0001 // Internet Explorer
(icon on desktop)
#define CSIDL_PROGRAMS 0x0002 // Start Menu\Programs
#define CSIDL_CONTROLS 0x0003 // My Computer\Control
Panel
#define CSIDL_PRINTERS 0x0004 // My
Computer\Printers
#define CSIDL_PERSONAL 0x0005 // My Documents
#define CSIDL_FAVORITES 0x0006 // <user
name>\Favorites
#define CSIDL_STARTUP 0x0007 // Start
Menu\Programs\Startup
#define CSIDL_RECENT 0x0008 // <user name>\Recent
#define CSIDL_SENDTO 0x0009 // <user name>\SendTo
#define CSIDL_BITBUCKET 0x000a // <desktop>\Recycle
Bin
#define CSIDL_STARTMENU 0x000b // <user name>\Start
Menu
#define CSIDL_MYDOCUMENTS 0x000c // logical "My
Documents" desktop icon
#define CSIDL_MYMUSIC 0x000d // "My Music" folder
#define CSIDL_MYVIDEO 0x000e // "My Videos" folder
#define CSIDL_DESKTOPDIRECTORY 0x0010 // <user name>\Desktop
#define CSIDL_DRIVES 0x0011 // My Computer
#define CSIDL_NETWORK 0x0012 // Network
Neighborhood (My Network Places)
#define CSIDL_NETHOOD 0x0013 // <user name>\nethood
#define CSIDL_FONTS 0x0014 // windows\fonts
#define CSIDL_TEMPLATES 0x0015
#define CSIDL_COMMON_STARTMENU 0x0016 // All Users\Start
Menu
#define CSIDL_COMMON_PROGRAMS 0X0017 // All Users\Start
Menu\Programs
#define CSIDL_COMMON_STARTUP 0x0018 // All Users\Startup
#define CSIDL_COMMON_DESKTOPDIRECTORY 0x0019 // All Users\Desktop
#define CSIDL_APPDATA 0x001a // <user
name>\Application Data
#define CSIDL_PRINTHOOD 0x001b // <user
name>\PrintHood
<snip>

(There are lots more defined.)

Andrew
 
A

andrews

Thanks for the information but I will repeat one of my questions
Can I put the font into the code in some of another (resources?)way so
that the font is always avalable for the program?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top