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 ); }
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 ); }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2