• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

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

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.


Peter
0
petershaw8
Asked:
petershaw8
  • 2
1 Solution
 
dunglaCommented:
You should change to 8F not 8. Here is the correct

Font font = new  Font( "Arial",  8F,  FontStyle.Regular,  GraphicsUnit.Display)
0
 
YurichCommented:
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

regards,
mik
0
 
YurichCommented:
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

regards,
mik
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now