Create() public static method

public static Create ( ) : ScreenDC
return ScreenDC
示例#1
0
 internal static Font FromLogFont(ref Interop.User32.LOGFONT logFont)
 {
     using (ScreenDC dc = ScreenDC.Create())
     {
         return(FromLogFont(logFont, dc));
     }
 }
示例#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));
     }
 }
示例#3
0
 internal static Font FromLogFont(ref SafeNativeMethods.LOGFONT logFont)
 {
     using (ScreenDC dc = ScreenDC.Create())
     {
         return(FromLogFont(logFont, dc));
     }
 }
示例#4
0
 public float GetHeight()
 {
     using (ScreenDC dc = ScreenDC.Create())
         using (Graphics graphics = Graphics.FromHdcInternal(dc))
         {
             return(GetHeight(graphics));
         }
 }
示例#5
0
 public void ToLogFont(object logFont)
 {
     using (ScreenDC dc = ScreenDC.Create())
         using (Graphics graphics = Graphics.FromHdcInternal(dc))
         {
             ToLogFont(logFont, graphics);
         }
 }
示例#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));
            }
        }
示例#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));
            }
        }
示例#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);
                }
        }
示例#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);
                }
        }