how to use public Font(string, float, FontStyle, GraphicsUnit);

Posted on 2005-05-05
Last Modified: 2013-12-03
I try to use public Font(string, float, FontStyle, GraphicsUnit); to create a font, like
        Font font = new  Font( "Arial",  8,  FontStyle.Regular,  GraphicsUnit.Display);
I got a runtime error, it said the parameter is invalid. How should I use this constructor?

Also I use Graphics.DrawString(string, Font, Brush, float, float, StringFormat); to write a character. I found the output is a little bit thick, is any way to produce a fine character?

Mnay thanks.

Question by:petershaw8
    LVL 13

    Expert Comment

    You should change to 8F not 8. Here is the correct

    Font font = new  Font( "Arial",  8F,  FontStyle.Regular,  GraphicsUnit.Display)
    LVL 21

    Expert Comment

    actually, it's nothing to do with float and size, it's GraphicsUnit.Display causes the trouble, try to use anything but Display, like:

    Font font = new  Font( "Arial",  8,  FontStyle.Regular,  GraphicsUnit.Point ); // or

    Font font = new  Font( "Arial",  8,  FontStyle.Regular,  GraphicsUnit.Pixel );  // or

    Font font = new  Font( "Arial",  8,  FontStyle.Regular,  GraphicsUnit.Millimeter );

    everything will work just fine

    LVL 21

    Accepted Solution

    and as for your character draing question.
    you should've used a big and bold font to get a thick character, for example:

    Graphics g = Graphics.FromHwnd( this.Handle );
    Font font = new Font( "Verdana", 10 );
    g.DrawString( "test", font, Brushes.Black, new Rectangle( 10, 10, 100, 20 ));

    using the code above, you'll get a nice neat line, not much bigger than you have on your controls


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    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…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 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

    20 Experts available now in Live!

    Get 1:1 Help Now