Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2ColorConverter.cs / 1 / COM2ColorConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.ComponentModel.Com2Interop { using System.Runtime.Serialization.Formatters; using System.ComponentModel; using System.Diagnostics; using System; using System.Drawing; using System.Collections; using Microsoft.Win32; ////// /// This class maps an OLE_COLOR to a managed Color editor. /// internal class Com2ColorConverter : Com2DataTypeToManagedDataTypeConverter{ ////// /// Returns the managed type that this editor maps the property type to. /// public override Type ManagedType{ get{ return typeof(Color); } } ////// /// Converts the native value into a managed value /// public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd){ object baseValue = nativeValue; int intVal = 0; // get the integer value out of the native... // if (nativeValue is UInt32){ intVal = (int)(UInt32)nativeValue; } else if (nativeValue is Int32){ intVal = (int)nativeValue; } return ColorTranslator.FromOle(intVal); } ////// /// Converts the managed value into a native value /// public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet){ // don't cancel the set cancelSet = false; // we default to black. // if (managedValue == null){ managedValue = Color.Black; } if (managedValue is Color){ return ColorTranslator.ToOle(((Color)managedValue)); } Debug.Fail("Don't know how to set type:" + managedValue.GetType().Name); return 0; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.ComponentModel.Com2Interop { using System.Runtime.Serialization.Formatters; using System.ComponentModel; using System.Diagnostics; using System; using System.Drawing; using System.Collections; using Microsoft.Win32; ////// /// This class maps an OLE_COLOR to a managed Color editor. /// internal class Com2ColorConverter : Com2DataTypeToManagedDataTypeConverter{ ////// /// Returns the managed type that this editor maps the property type to. /// public override Type ManagedType{ get{ return typeof(Color); } } ////// /// Converts the native value into a managed value /// public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd){ object baseValue = nativeValue; int intVal = 0; // get the integer value out of the native... // if (nativeValue is UInt32){ intVal = (int)(UInt32)nativeValue; } else if (nativeValue is Int32){ intVal = (int)nativeValue; } return ColorTranslator.FromOle(intVal); } ////// /// Converts the managed value into a native value /// public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet){ // don't cancel the set cancelSet = false; // we default to black. // if (managedValue == null){ managedValue = Color.Black; } if (managedValue is Color){ return ColorTranslator.ToOle(((Color)managedValue)); } Debug.Fail("Don't know how to set type:" + managedValue.GetType().Name); return 0; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataSourceCacheDurationConverter.cs
- CopyNodeSetAction.cs
- xmlfixedPageInfo.cs
- ZipIOLocalFileHeader.cs
- DesignerTransaction.cs
- Attribute.cs
- SqlFactory.cs
- WindowsRichEdit.cs
- ObjectAnimationUsingKeyFrames.cs
- WebPartConnectionsCancelVerb.cs
- FormParameter.cs
- HttpInputStream.cs
- ThicknessConverter.cs
- EdmEntityTypeAttribute.cs
- SqlErrorCollection.cs
- ApplicationInfo.cs
- HttpPostedFile.cs
- CheckedListBox.cs
- SqlCachedBuffer.cs
- Vector3DAnimationBase.cs
- BamlResourceDeserializer.cs
- TcpAppDomainProtocolHandler.cs
- SecureStringHasher.cs
- FunctionDetailsReader.cs
- CodeIdentifier.cs
- Helpers.cs
- PartialArray.cs
- EncryptedKey.cs
- WindowsListViewItemCheckBox.cs
- KoreanCalendar.cs
- DataTemplateSelector.cs
- MembershipValidatePasswordEventArgs.cs
- DataGridViewCellFormattingEventArgs.cs
- AsymmetricCryptoHandle.cs
- HGlobalSafeHandle.cs
- DataGridViewBand.cs
- CreateRefExpr.cs
- TrustSection.cs
- DataServiceExpressionVisitor.cs
- CodeCastExpression.cs
- FigureParagraph.cs
- DecoderExceptionFallback.cs
- ObjectComplexPropertyMapping.cs
- PackageRelationship.cs
- ToolStripLabel.cs
- PlatformCulture.cs
- PageRouteHandler.cs
- DataGridAutomationPeer.cs
- ColumnClickEvent.cs
- RequestCachingSection.cs
- FontDialog.cs
- FrameworkElementAutomationPeer.cs
- ProjectionRewriter.cs
- EntityDataSource.cs
- RootBrowserWindowAutomationPeer.cs
- HttpGetProtocolImporter.cs
- FontFamilyIdentifier.cs
- WasHttpHandlersInstallComponent.cs
- StringAnimationBase.cs
- SystemFonts.cs
- NamespaceQuery.cs
- ExpandoClass.cs
- JsonCollectionDataContract.cs
- SocketException.cs
- TreeNodeEventArgs.cs
- ItemContainerProviderWrapper.cs
- RelOps.cs
- TextEditorLists.cs
- SortedList.cs
- EventMappingSettingsCollection.cs
- InteropExecutor.cs
- DockPattern.cs
- WebDisplayNameAttribute.cs
- SqlNode.cs
- PerformanceCountersElement.cs
- IgnoreSectionHandler.cs
- RNGCryptoServiceProvider.cs
- ErrorWrapper.cs
- OAVariantLib.cs
- SafeFileMapViewHandle.cs
- ChannelManager.cs
- WebPart.cs
- EnumValAlphaComparer.cs
- AjaxFrameworkAssemblyAttribute.cs
- JsonServiceDocumentSerializer.cs
- LinqDataView.cs
- AggregateNode.cs
- IERequestCache.cs
- DataSourceCacheDurationConverter.cs
- HtmlFormAdapter.cs
- VectorAnimation.cs
- DateTimePicker.cs
- _NegotiateClient.cs
- XmlSchemaSimpleTypeUnion.cs
- DataListItemEventArgs.cs
- BaseValidator.cs
- StubHelpers.cs
- PropertyTab.cs
- SQLBytesStorage.cs
- MulticastOption.cs