Simple wrapper to create a screen HDC within a using statement.
Example #1
0
 internal static Font FromLogFont(ref Interop.User32.LOGFONT logFont)
 {
     using (ScreenDC dc = ScreenDC.Create())
     {
         return(FromLogFont(logFont, dc));
     }
 }
Example #2
0
 /// <summary>
 /// Creates a <see cref="Font"/> from the given LOGFONT using the screen device context.
 /// </summary>
 /// <param name="lf">A boxed LOGFONT.</param>
 /// <returns>The newly created <see cref="Font"/>.</returns>
 public static Font FromLogFont(object lf)
 {
     using (ScreenDC dc = ScreenDC.Create())
     {
         return(FromLogFont(lf, dc));
     }
 }
Example #3
0
 internal static Font FromLogFont(ref SafeNativeMethods.LOGFONT logFont)
 {
     using (ScreenDC dc = ScreenDC.Create())
     {
         return(FromLogFont(logFont, dc));
     }
 }
Example #4
0
 public float GetHeight()
 {
     using (ScreenDC dc = ScreenDC.Create())
         using (Graphics graphics = Graphics.FromHdcInternal(dc))
         {
             return(GetHeight(graphics));
         }
 }
Example #5
0
 public void ToLogFont(object logFont)
 {
     using (ScreenDC dc = ScreenDC.Create())
         using (Graphics graphics = Graphics.FromHdcInternal(dc))
         {
             ToLogFont(logFont, graphics);
         }
 }
Example #6
0
        /// <summary>
        /// Creates a <see cref='Font'/> from the specified Windows handle.
        /// </summary>
        public static Font FromHfont(IntPtr hfont)
        {
            Interop.User32.LOGFONT logFont = default;
            Interop.Gdi32.GetObject(new HandleRef(null, hfont), ref logFont);

            using (ScreenDC dc = ScreenDC.Create())
            {
                return(FromLogFontInternal(ref logFont, dc));
            }
        }
Example #7
0
        /// <summary>
        /// Creates a <see cref='Font'/> from the specified Windows handle.
        /// </summary>
        public static Font FromHfont(IntPtr hfont)
        {
            var logFont = new SafeNativeMethods.LOGFONT();

            SafeNativeMethods.GetObject(new HandleRef(null, hfont), ref logFont);

            using (ScreenDC dc = ScreenDC.Create())
            {
                return(FromLogFontInternal(ref logFont, dc));
            }
        }
Example #8
0
        /// <summary>
        /// Returns a handle to this <see cref='Font'/>.
        /// </summary>
        public IntPtr ToHfont()
        {
            using (ScreenDC dc = ScreenDC.Create())
                using (Graphics graphics = Graphics.FromHdcInternal(dc))
                {
                    Interop.User32.LOGFONT lf = ToLogFontInternal(graphics);
                    IntPtr handle             = Interop.Gdi32.CreateFontIndirectW(ref lf);
                    if (handle == IntPtr.Zero)
                    {
                        throw new Win32Exception();
                    }

                    return(handle);
                }
        }
Example #9
0
        /// <summary>
        /// Returns a handle to this <see cref='Font'/>.
        /// </summary>
        public IntPtr ToHfont()
        {
            using (ScreenDC dc = ScreenDC.Create())
                using (Graphics graphics = Graphics.FromHdcInternal(dc))
                {
                    SafeNativeMethods.LOGFONT lf = ToLogFontInternal(graphics);
                    IntPtr handle = IntUnsafeNativeMethods.CreateFontIndirect(ref lf);
                    if (handle == IntPtr.Zero)
                    {
                        throw new Win32Exception();
                    }

                    return(handle);
                }
        }