⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq75.htm

📁 C++builder学习资料C++builder
💻 HTM
字号:


<HTML>

<HEAD>

   <TITLE>Find out which fonts are installed on a computer</TITLE>

   <META NAME="Author" CONTENT="Harold Howe">

</HEAD>

<BODY BGCOLOR="WHITE">



<CENTER>

<TABLE  BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">



<TR>

<TD>









<H3>

Find out which fonts are installed on a computer

</H3>



<P>

The API contains a host of <TT>EnumFontXXXX</TT> that allow you to query the OS for many different font properties.

Usually you just want to know if a system supports a specific font, such as Courier or Times New Roman. If this is the

case, the easiest way to determine if a system supports a font is to check the <TT>Fonts</TT> property of the global

<TT>Screen</TT> object. The <TT>TPrinter</TT> class has a similar <TT>Fonts</TT> property.

</P>

<P>

The following code example fills a listbox with all of the fonts that are installed on a machine. When the user selects

an item from the listbox, the font of a label changes to match.

</P>

<pre>

<b>__fastcall</b> TForm1<b>:</b><b>:</b>TForm1<b>(</b>TComponent<b>*</b> Owner<b>)</b>

    <b>:</b> TForm<b>(</b>Owner<b>)</b>

<b>{</b>

    <font color="navy">// fill the listbox with the strings from the</font>

    <font color="navy">// Fonts property of the global screen object</font>

    ListBox1<b>-></b>Items<b>-></b>Assign<b>(</b>Screen<b>-></b>Fonts<b>)</b><b>;</b>

    ListBox1<b>-></b>ItemIndex <b>=</b> <font color="blue">0</font><b>;</b>

<b>}</b>

<font color="navy">//------------------------------------------------------------</font>

<b>void</b> <b>__fastcall</b> TForm1<b>:</b><b>:</b>ListBox1Click<b>(</b>TObject <b>*</b>Sender<b>)</b>

<b>{</b>

    <font color="navy">// Change the font of a label based on the listbox selection</font>

    Label1<b>-></b>Font<b>-></b>Name <b>=</b> ListBox1<b>-></b>Items<b>-></b>Strings<b>[</b>ListBox1<b>-></b>ItemIndex<b>]</b><b>;</b>

<b>}</b>

</pre>

<P>

The <TT>Fonts</TT> property of <TT>TScreen</TT> is a <TT>TStringList</TT>. <TT>TStringList</TT> provides an

<TT>IndexOf</TT> method that searches the list for a specific string. The following code shows how to use the

<TT>IndexOf</TT> method to determine if a font is installed.

</P>

<pre>

<b>void</b> <b>__fastcall</b> TForm1<b>:</b><b>:</b>Button1Click<b>(</b>TObject <b>*</b>Sender<b>)</b>

<b>{</b>

    <font color="navy">// IndexOf returns the index of the string in the list if</font>

    <font color="navy">// the string is found. If not found, it returns -1</font>

    <b>if</b><b>(</b>Screen<b>-></b>Fonts<b>-></b>IndexOf<b>(</b><font color="blue">"Courier New"</font><b>)</b> <b>>=</b> <font color="blue">0</font><b>)</b>

        ShowMessage<b>(</b><font color="blue">"Courier New is installed"</font><b>)</b><b>;</b>

    <b>else</b>

        ShowMessage<b>(</b><font color="blue">"Courier New not found"</font><b>)</b><b>;</b>

<b>}</b>

</pre>



</TD> </TR>



</TABLE>

</CENTER>

</BODY>

</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -