Exemplo n.º 1
0
        /// <include file='doc\Font.uex' path='docs/doc[@for="Font.FromHdc"]/*' />
        /// <devdoc>
        ///    Creates a Font from the specified Windows
        ///    handle to a device context.
        /// </devdoc>
        public static Font FromHdc(IntPtr hdc)
        {
            IntSecurity.ObjectFromWin32Handle.Demand();

            IntPtr font = IntPtr.Zero;

            int status = SafeNativeMethods.GdipCreateFontFromDC(new HandleRef(null, hdc), ref font);

            // Special case this incredibly common error message to give more information
            if (status == SafeNativeMethods.NotTrueTypeFont)
            {
                throw new ArgumentException(SR.GetString(SR.GdiplusNotTrueTypeFont_NoName));
            }
            else if (status != SafeNativeMethods.Ok)
            {
                throw SafeNativeMethods.StatusException(status);
            }

            return(new Font(font, 0, false));
        }