public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet) { // we default to black. if (managedValue == null) { managedValue = Control.DefaultFont; } cancelSet = true; if (_lastFont != null && _lastFont.Equals(managedValue)) { // don't do anything here. return(null); } _lastFont = (Font)managedValue; Ole32.IFont nativeFont = (Ole32.IFont)pd.GetNativeValue(pd.TargetObject); // now, push all the values into the native side if (nativeFont != null) { bool changed = ControlPaint.FontToIFont(_lastFont, nativeFont); if (changed) { // here, we want to pick up a new font from the handle _lastFont = null; ConvertNativeToManaged(nativeFont, pd); } } return(null); }
public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet) { if (managedValue == null) { managedValue = Control.DefaultFont; } cancelSet = true; if ((this.lastFont == null) || !this.lastFont.Equals(managedValue)) { this.lastFont = (Font)managedValue; System.Windows.Forms.UnsafeNativeMethods.IFont nativeValue = (System.Windows.Forms.UnsafeNativeMethods.IFont)pd.GetNativeValue(pd.TargetObject); if ((nativeValue != null) && ControlPaint.FontToIFont(this.lastFont, nativeValue)) { this.lastFont = null; this.ConvertNativeToManaged(nativeValue, pd); } } return(null); }