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
- HtmlElementEventArgs.cs
- GridLengthConverter.cs
- SingleQueryOperator.cs
- StoreItemCollection.cs
- FieldMetadata.cs
- MatrixTransform.cs
- SvcMapFileSerializer.cs
- AsymmetricAlgorithm.cs
- DataGridLength.cs
- EventRoute.cs
- DesignBinding.cs
- NameValuePermission.cs
- RightsManagementResourceHelper.cs
- ListChangedEventArgs.cs
- XamlGridLengthSerializer.cs
- DataGridViewCheckBoxColumn.cs
- Vector3D.cs
- ConfigurationErrorsException.cs
- FormViewPageEventArgs.cs
- BaseResourcesBuildProvider.cs
- XmlIncludeAttribute.cs
- SqlCommandBuilder.cs
- Label.cs
- AsyncResult.cs
- TraceHandlerErrorFormatter.cs
- MatrixStack.cs
- BamlLocalizableResource.cs
- SecurityProtocolCorrelationState.cs
- querybuilder.cs
- SortAction.cs
- RangeBase.cs
- TextTabProperties.cs
- OdbcCommand.cs
- CannotUnloadAppDomainException.cs
- XNodeNavigator.cs
- ObjRef.cs
- SynchronizationValidator.cs
- _ShellExpression.cs
- RemotingConfigParser.cs
- LocatorGroup.cs
- SiteMapNode.cs
- FreezableOperations.cs
- UnsafeNativeMethodsPenimc.cs
- WebService.cs
- HyperLink.cs
- FuncTypeConverter.cs
- rsa.cs
- FunctionNode.cs
- Context.cs
- Vector3DConverter.cs
- BitStream.cs
- PathParser.cs
- XamlToRtfParser.cs
- _SSPISessionCache.cs
- NextPreviousPagerField.cs
- VariableAction.cs
- RelationshipDetailsCollection.cs
- StreamProxy.cs
- EventQueueState.cs
- ImportCatalogPart.cs
- DbgCompiler.cs
- TagPrefixCollection.cs
- HtmlInputRadioButton.cs
- DataListItemEventArgs.cs
- ContentAlignmentEditor.cs
- DataGridViewTopRowAccessibleObject.cs
- XmlEntityReference.cs
- StubHelpers.cs
- Pens.cs
- X509CertificateCollection.cs
- CatalogZoneBase.cs
- SchemaCreator.cs
- OutputCacheSettings.cs
- OrderPreservingMergeHelper.cs
- DataView.cs
- MetadataArtifactLoaderCompositeFile.cs
- Win32SafeHandles.cs
- TemplateControlParser.cs
- TextEditorThreadLocalStore.cs
- TextRunCacheImp.cs
- BitmapEffectGroup.cs
- SafeCertificateContext.cs
- SafeRightsManagementEnvironmentHandle.cs
- SecurityDocument.cs
- OletxVolatileEnlistment.cs
- DataGridViewRowsRemovedEventArgs.cs
- HealthMonitoringSection.cs
- Vector3D.cs
- SqlDataSourceQuery.cs
- HtmlLink.cs
- GlyphingCache.cs
- PasswordBox.cs
- PngBitmapDecoder.cs
- TextServicesContext.cs
- DocumentProperties.cs
- EdmItemCollection.cs
- ComboBox.cs
- DataSourceIDConverter.cs
- DataTableMapping.cs
- DBSqlParserColumnCollection.cs