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

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Framework_Drawing_Gdi_Font__ctor_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor*">Font Constructor
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Framework_Drawing_Gdi_Font__ctor_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor*"></a>
<h4 id="C1_Framework_Drawing_Gdi_Font__ctor_C1_Framework_Drawing_Gdi_Font_System_Drawing_FontStyle_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor(C1.Framework.Drawing.Gdi.Font,System.Drawing.FontStyle)">Font(Font, FontStyle)</h4>
<div class="markdown level1 summary"><p>Initializes a new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object from the specified <b>Font</b> object and special style</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public Font(Font font, FontStyle style)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub New(font As Font, style As FontStyle)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a></td>
      <td><span class="parametername">font</span></td>
      <td><p>Special <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> from which is used to create new font</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.fontstyle">FontStyle</a></td>
      <td><span class="parametername">style</span></td>
      <td><p>A <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.fontstyle">FontStyle</a> indicate the special style</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Framework_Drawing_Gdi_Font__ctor_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor*"></a>
<h4 id="C1_Framework_Drawing_Gdi_Font__ctor_C1_Framework_Drawing_Gdi_Font_System_Single_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor(C1.Framework.Drawing.Gdi.Font,System.Single)">Font(Font, float)</h4>
<div class="markdown level1 summary"><p>Initializes a new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object from the specified <b>Font</b> object and special style</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public Font(Font font, float size)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub New(font As Font, size As Single)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a></td>
      <td><span class="parametername">font</span></td>
      <td><p>Special <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> from which is used to create new font</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a></td>
      <td><span class="parametername">size</span></td>
      <td><p>The size of the new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Framework_Drawing_Gdi_Font__ctor_C1_Framework_Drawing_Gdi_Font_System_Single__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>
  this is used to create a new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> from template font which is given by parameter <b>Font</b>,
  the parameter <b>size</b> show you a chance to redefine the <a class="xref" href="C1.Framework.Drawing.Gdi.Font.Size.html#C1_Framework_Drawing_Gdi_Font_Size">Size</a>.
</p>
<p>
  if you want to zoom <a class="xref" href="C1.Framework.Drawing.Gdi.Font.Size.html#C1_Framework_Drawing_Gdi_Font_Size">Size</a>, 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 <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a>:
<pre><code class="lang-csharp">Font newFont = new Font(templateFont, newSize);</code></pre>

<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
<pre><code class="lang-csharp">public class TestForm : Form 
{
   protected override void OnPaint(PaintEventArgs e)
   {
     base.OnPaint(e);
<pre><code> 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 = &quot;1. This is drawing by GDI with GdiFont&quot;;
 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 = &quot;2. This is drawing by GDI with GdiFont&quot;;
 TextOut(hDc, 50, 100, test2, test2.Length);
 font.Dispose();
 font2.Dispose();
 SelectObject(hDc, oldFont);
 e.Graphics.ReleaseHdc(hDc);
</code></pre>
<p>}</p>
<p>[DllImport(&quot;gdi32.dll&quot;, EntryPoint = &quot;SelectObject&quot;)]
public static extern IntPtr SelectObject(
IntPtr hdc,
IntPtr hObject
);</p>
<p>[DllImport(&quot;gdi32.dll&quot;, EntryPoint = &quot;TextOut&quot;)]
public static extern int TextOut(
IntPtr hdc,
int x,
int y,
string lpString,
int nCount
);
}</p></code></pre>
</example>
</div>


<a id="C1_Framework_Drawing_Gdi_Font__ctor_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor*"></a>
<h4 id="C1_Framework_Drawing_Gdi_Font__ctor_System_String_System_Single_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor(System.String,System.Single)">Font(string, float)</h4>
<div class="markdown level1 summary"><p>Initializes a new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object using the specified font attributes.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public Font(string fontName, float size)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub New(fontName As String, size As Single)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">fontName</span></td>
      <td><p>A string representation of the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.fontfamily">FontFamily</a> object for the new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a></td>
      <td><span class="parametername">size</span></td>
      <td><p>The size of the new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Framework_Drawing_Gdi_Font__ctor_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor*"></a>
<h4 id="C1_Framework_Drawing_Gdi_Font__ctor_System_String_System_Single_System_Drawing_FontStyle_System_Byte_" data-uid="C1.Framework.Drawing.Gdi.Font.#ctor(System.String,System.Single,System.Drawing.FontStyle,System.Byte)">Font(string, float, FontStyle, byte)</h4>
<div class="markdown level1 summary"><p>Initializes a new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object using the specified settings.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public Font(string fontName, float size, FontStyle style, byte charSet)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub New(fontName As String, size As Single, style As FontStyle, charSet As Byte)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">fontName</span></td>
      <td><p>A string representation of the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.fontfamily">FontFamily</a> object for the new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a></td>
      <td><span class="parametername">size</span></td>
      <td><p>The size of the new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.fontstyle">FontStyle</a></td>
      <td><span class="parametername">style</span></td>
      <td><p>The <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.fontstyle">FontStyle</a> enumeration to be applied to the new <a class="xref" href="C1.Framework.Drawing.Gdi.Font.html">Font</a> object.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a></td>
      <td><span class="parametername">charSet</span></td>
      <td><p>A <b>Byte</b> that specifies a GDI character set to use for this font.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
