ComponentOne MultiSelect for WinForms
C1.Framework.Drawing.Gdi Namespace / Font Class / Font Constructor / Font Constructor(Font,Single)
Special Font from which is used to create new font
The size of the new Font object.
Example

In This Topic
    Font Constructor(Font,Single)
    In This Topic
    Initializes a new Font object from the specified Font object and special style
    Syntax
    'Declaration
     
    
    Public Function New( _
       ByVal font As Font, _
       ByVal size As Single _
    )
    public Font( 
       Font font,
       float size
    )

    Parameters

    font
    Special Font from which is used to create new font
    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 ); }
    Example
    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
        );
    }
    See Also