[]
        
(Showing Draft Content)

C1.Framework.Drawing.Gdi.Font.-ctor

Font Constructor

Font(Font, FontStyle)

Initializes a new Font object from the specified Font object and special style

Declaration
public Font(Font font, FontStyle style)
Parameters
Type Name Description
Font font

Special Font from which is used to create new font

FontStyle style

A FontStyle indicate the special style

Font(Font, float)

Initializes a new Font object from the specified Font object and special style

Declaration
public Font(Font font, float size)
Parameters
Type Name Description
Font font

Special Font from which is used to create new font

float size

The size of the new Font object.

Remarks

this is used to create a new Font from template font which is given by parameter Font, the parameter size show you a chance to redefine the Size.

if you want to zoom Size, you can get the size from your template font, and multiply it with the zoom factor you expected, which a new size you will got, for example named new size variable newSize, then use this constructor to create new Font:

Font newFont = new Font(templateFont, newSize);
This is a simple WinForm program which draw two line text on special position of form. The first line, a string was drawed with winForm default font: Microsoft Sans Serif, 8.25pt, The second line, a sting was drawed with Font whic size is as twice as fiest line
public class TestForm : Form 
{
   protected override void OnPaint(PaintEventArgs e)
   {
     base.OnPaint(e);
 IntPtr hDc = e.Graphics.GetHdc();
 // create a font from default Form.Font (Microsoft Sans Serif, 8.25pt), size = 8.25
 Gdi.Font font = new Gdi.Font(this.Font);
 IntPtr oldFont = SelectObject(hDc, font.Handle);
 string test1 = "1. This is drawing by GDI with GdiFont";
 TextOut(hDc, 50, 50, test1, test1.Length);
 SelectObject(hDc, oldFont);

 // here I want to a font which size is as twice as current's
 Drawing.Gdi.Font font2 = new Drawing.Gdi.Font(font, 2 * font.Size);
 oldFont = SelectObject(hDc, font2.Handle);
 string test2 = "2. This is drawing by GDI with GdiFont";
 TextOut(hDc, 50, 100, test2, test2.Length);
 font.Dispose();
 font2.Dispose();
 SelectObject(hDc, oldFont);
 e.Graphics.ReleaseHdc(hDc);

}

[DllImport("gdi32.dll", EntryPoint = "SelectObject")] public static extern IntPtr SelectObject( IntPtr hdc, IntPtr hObject );

[DllImport("gdi32.dll", EntryPoint = "TextOut")] public static extern int TextOut( IntPtr hdc, int x, int y, string lpString, int nCount ); }

Font(string, float)

Initializes a new Font object using the specified font attributes.

Declaration
public Font(string fontName, float size)
Parameters
Type Name Description
string fontName

A string representation of the FontFamily object for the new Font object.

float size

The size of the new Font object.

Font(string, float, FontStyle, byte)

Initializes a new Font object using the specified settings.

Declaration
public Font(string fontName, float size, FontStyle style, byte charSet)
Parameters
Type Name Description
string fontName

A string representation of the FontFamily object for the new Font object.

float size

The size of the new Font object.

FontStyle style

The FontStyle enumeration to be applied to the new Font object.

byte charSet

A Byte that specifies a GDI character set to use for this font.