ComponentOne Word for WinForms
Working with Word for WinForms / Advanced Level Working / Adding Fonts
In This Topic
    Adding Fonts
    In This Topic

    Using the right font makes the document stand out. You may want to create a document with a variety of font styles to display every text written in different font style appear distinct. You can use different fonts to your word document using the following code:

    ' draw text in many fonts
    Dim font As New Font("Tahoma", 9)
    Dim ifc As New InstalledFontCollection()
    For Each ff As FontFamily In ifc.Families
            ' create font
            Dim sample As Font = Nothing
            For Each fs As FontStyle In [Enum].GetValues(GetType(FontStyle))
                    If ff.IsStyleAvailable(fs) Then
                            sample = New Font(ff.Name, 9, fs)
                            Exit For
                    End If
            Next
            If sample Is Nothing Then
                    Continue For
            End If
    
            ' show font
            C1Word.AddParagraph(ff.Name, font, Color.Black)
            C1Word.AddParagraph("The quick brown fox jumped over the lazy dog. 1234567890!", sample, Color.Black)
            sample.Dispose()
    Next
                                    
    
    // draw text in many fonts
    Font font = new Font("Tahoma", 9);
    InstalledFontCollection ifc = new InstalledFontCollection();
    foreach (FontFamily ff in ifc.Families)
    {
            // create font
            Font sample = null;
            foreach (FontStyle fs in Enum.GetValues(typeof(FontStyle)))
            {
                    if (ff.IsStyleAvailable(fs))
                    {
                            sample = new Font(ff.Name, 9, fs);
                            break;
                    }
            }
            if (sample == null) continue;
    
            // show font
            C1Word.AddParagraph(ff.Name, font, Color.Black);
            C1Word.AddParagraph("The quick brown fox jumped over the lazy dog. 1234567890!", sample, Color.Black);
            sample.Dispose();
    }