[]
Initializes a new Font object from the specified Font object and special style
public Font(Font font, FontStyle style)
Type | Name | Description |
---|---|---|
Font | font | Special Font from which is used to create new font |
FontStyle | style | A FontStyle indicate the special style |
Initializes a new Font object from the specified Font object and special style
public Font(Font font, float size)
Type | Name | Description |
---|---|---|
Font | font | Special Font from which is used to create new font |
float | size | The size of the new Font object. |
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);
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
);
}
Initializes a new Font object using the specified font attributes.
public Font(string fontName, float size)
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. |
Initializes a new Font object using the specified settings.
public Font(string fontName, float size, FontStyle style, byte charSet)
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. |