Ejemplo n.º 1
0
        public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd)
        {
            System.Windows.Forms.UnsafeNativeMethods.IFont font = nativeValue as System.Windows.Forms.UnsafeNativeMethods.IFont;
            if (font == null)
            {
                this.lastHandle = IntPtr.Zero;
                this.lastFont   = Control.DefaultFont;
                return(this.lastFont);
            }
            IntPtr hFont = font.GetHFont();

            if ((hFont != this.lastHandle) || (this.lastFont == null))
            {
                this.lastHandle = hFont;
                try
                {
                    using (Font font2 = Font.FromHfont(this.lastHandle))
                    {
                        this.lastFont = ControlPaint.FontInPoints(font2);
                    }
                }
                catch (ArgumentException)
                {
                    this.lastFont = Control.DefaultFont;
                }
            }
            return(this.lastFont);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Converts the native value into a managed value
        /// </summary>
        public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd)
        {
            // we're getting an IFont thing here

            if (!(nativeValue is UnsafeNativeMethods.IFont nativeFont))
            {
                lastHandle = IntPtr.Zero;
                lastFont   = Control.DefaultFont;
                return(lastFont);
            }

            IntPtr fontHandle = nativeFont.GetHFont();

            // see if we have this guy cached
            if (fontHandle == lastHandle && lastFont != null)
            {
                return(lastFont);
            }

            lastHandle = fontHandle;

            try
            {
                // this wasn't working because it was converting everything to
                // world units.
                //
                Font font = Font.FromHfont(lastHandle);
                try
                {
                    lastFont = ControlPaint.FontInPoints(font);
                }
                finally
                {
                    font.Dispose();
                }
            }
            catch (ArgumentException)
            {
                // we will fail on non-truetype fonts, so
                // just use the default font.
                lastFont = Control.DefaultFont;
            }

            return(lastFont);
        }
Ejemplo n.º 3
0
        public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd)
        {
            // we're getting an IFont here
            if (!(nativeValue is Ole32.IFont nativeFont))
            {
                _lastHandle = IntPtr.Zero;
                _lastFont   = Control.DefaultFont;
                return(_lastFont);
            }

            IntPtr fontHandle = nativeFont.hFont;

            // see if we have this guy cached
            if (fontHandle == _lastHandle && _lastFont != null)
            {
                return(_lastFont);
            }

            _lastHandle = fontHandle;

            try
            {
                // this wasn't working because it was converting everything to
                // world units.
                using (Font font = Font.FromHfont(_lastHandle))
                {
                    _lastFont = ControlPaint.FontInPoints(font);
                }
            }
            catch (ArgumentException)
            {
                // we will fail on non-truetype fonts, so
                // just use the default font.
                _lastFont = Control.DefaultFont;
            }

            return(_lastFont);
        }