Using Multiple fonts in a Control

Posted on 2006-05-31
Last Modified: 2013-12-03
I am using C# and I want to be able to use multiple fonts, font sizes in a control.  Specifically I want to be able to display a bar code font, and then a regular fotn right below it in a text box or a rich text box.  I then want to be able to print this data.  I'm not sure how to display multiple fonts in the control.
Question by:rshooper76
    LVL 96

    Accepted Solution

    With a RichTextBox, here is an example:

    Font h1 = new Font("Tahoma", 14, FontStyle.Bold);
    Font h2 = new Font("Tahoma", 10);

    rtf.SelectionFont = h1;
    rtf.AppendText("Heading 1");
    rtf.SelectionFont = h2;
    rtf.AppendText("Heading 2");


    LVL 2

    Expert Comment

    LVL 2

    Expert Comment

    Hi rshooper76,

    I had to do more or less the same thing for a postal application I was working on. The application needed to display an address, and at the top display the barcode equivalent of some number in the address.

    What I ended up doing was using a label or (border-less TextBox) for writing the string in barcode font there, and then I put (in my case) a multiline textbox (also borderless) right underneath for the address. For all purposes, it looked like they were in the same control.

    The only problem I had was with the barcode font. Several of the clients didn't have the barcode font installed so I had to manually install it during the program installation.  The weird thing was that File.Copy doesn't work: you either have to copy the file into the Windows Font folder  with Windows Explorer (it automatically runs an installation process)or use the the classes provided by .Net for these things.

    Hope this helps,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now