Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2ColorConverter.cs / 1305376 / 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
- RegexReplacement.cs
- HttpListenerContext.cs
- FrameworkTemplate.cs
- Button.cs
- TreeNodeBinding.cs
- ObjectQueryProvider.cs
- Line.cs
- DataControlPagerLinkButton.cs
- GenerateScriptTypeAttribute.cs
- MailAddress.cs
- TextLineBreak.cs
- MonthChangedEventArgs.cs
- SettingsBase.cs
- TextEndOfLine.cs
- TextTreeRootNode.cs
- GridViewAutomationPeer.cs
- WebRequestModuleElementCollection.cs
- sqlser.cs
- Verify.cs
- SpecialFolderEnumConverter.cs
- ControlBuilder.cs
- ButtonChrome.cs
- Int64KeyFrameCollection.cs
- OpenCollectionAsyncResult.cs
- CacheHelper.cs
- RecordBuilder.cs
- Shape.cs
- filewebrequest.cs
- WebPartCollection.cs
- DeliveryStrategy.cs
- WindowsMenu.cs
- XPathNodeInfoAtom.cs
- PersonalizablePropertyEntry.cs
- XamlBrushSerializer.cs
- IntSecurity.cs
- Currency.cs
- UIElement3D.cs
- SafeNativeMethods.cs
- SystemWebSectionGroup.cs
- MultiBinding.cs
- CryptoConfig.cs
- EdmFunction.cs
- RepeaterItemEventArgs.cs
- DBAsyncResult.cs
- GridViewColumnCollectionChangedEventArgs.cs
- SocketPermission.cs
- TextEditorLists.cs
- BasicKeyConstraint.cs
- SqlConnectionManager.cs
- DateTimeFormatInfo.cs
- WorkflowDefinitionDispenser.cs
- BinaryReader.cs
- DocumentAutomationPeer.cs
- DBBindings.cs
- LinkClickEvent.cs
- CorrelationHandle.cs
- SqlColumnizer.cs
- MouseCaptureWithinProperty.cs
- DataDocumentXPathNavigator.cs
- TimelineClockCollection.cs
- DoubleStorage.cs
- GroupJoinQueryOperator.cs
- ManipulationInertiaStartingEventArgs.cs
- VirtualizedCellInfoCollection.cs
- XmlIlVisitor.cs
- QueryRewriter.cs
- ProviderConnectionPointCollection.cs
- _NtlmClient.cs
- ReadOnlyDictionary.cs
- PointCollection.cs
- ToolZone.cs
- ProtocolProfile.cs
- DataGridViewTextBoxEditingControl.cs
- NgenServicingAttributes.cs
- PresentationSource.cs
- FunctionOverloadResolver.cs
- ObjectToIdCache.cs
- DataBoundControlHelper.cs
- ControlUtil.cs
- OdbcStatementHandle.cs
- TextTreeNode.cs
- OracleColumn.cs
- CodeParameterDeclarationExpression.cs
- XmlSortKey.cs
- TdsParser.cs
- ServerValidateEventArgs.cs
- GridViewItemAutomationPeer.cs
- BaseComponentEditor.cs
- MachineKeySection.cs
- DataList.cs
- SapiGrammar.cs
- CustomAttributeSerializer.cs
- ColorConvertedBitmapExtension.cs
- NonSerializedAttribute.cs
- TimersDescriptionAttribute.cs
- XPathAncestorIterator.cs
- DbConnectionHelper.cs
- IODescriptionAttribute.cs
- IncrementalHitTester.cs
- PipelineModuleStepContainer.cs