Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- DataRowView.cs
- DocumentViewerBaseAutomationPeer.cs
- TextViewBase.cs
- StringConcat.cs
- FontStretchConverter.cs
- StringResourceManager.cs
- BamlRecordWriter.cs
- HTTPNotFoundHandler.cs
- ItemAutomationPeer.cs
- StaticTextPointer.cs
- PresentationAppDomainManager.cs
- CharacterBuffer.cs
- SpeechEvent.cs
- ParameterToken.cs
- DbConnectionPoolGroup.cs
- SmtpFailedRecipientException.cs
- ParserContext.cs
- CodeMemberEvent.cs
- DataGridItem.cs
- IResourceProvider.cs
- SafeArrayRankMismatchException.cs
- HeaderedContentControl.cs
- OpenFileDialog.cs
- DBConnectionString.cs
- MbpInfo.cs
- ObjectTypeMapping.cs
- ImageListStreamer.cs
- UnsafeNativeMethods.cs
- Thickness.cs
- GroupItemAutomationPeer.cs
- RefType.cs
- HighlightVisual.cs
- Visual3D.cs
- FixedSOMPage.cs
- Selection.cs
- TransportListener.cs
- Tracking.cs
- Italic.cs
- MediaCommands.cs
- ProxyWebPartManager.cs
- PolyBezierSegmentFigureLogic.cs
- DataViewListener.cs
- CheckBox.cs
- DataObject.cs
- CustomDictionarySources.cs
- PackageRelationshipSelector.cs
- IncrementalHitTester.cs
- CodeEventReferenceExpression.cs
- CqlGenerator.cs
- XmlUtil.cs
- WebServiceClientProxyGenerator.cs
- InkCanvasInnerCanvas.cs
- LongValidator.cs
- ManagedWndProcTracker.cs
- WCFBuildProvider.cs
- SmiContext.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- DataBoundControlAdapter.cs
- DateTimeConverter2.cs
- OdbcFactory.cs
- ReferenceEqualityComparer.cs
- VerticalAlignConverter.cs
- EntityContainer.cs
- MimeFormatter.cs
- DmlSqlGenerator.cs
- RowToFieldTransformer.cs
- ErrorStyle.cs
- MessageDecoder.cs
- XappLauncher.cs
- FieldAccessException.cs
- ExceptionNotification.cs
- UniqueEventHelper.cs
- CurrencyWrapper.cs
- UnknownBitmapEncoder.cs
- ExpressionsCollectionEditor.cs
- XsltFunctions.cs
- CutCopyPasteHelper.cs
- WorkflowOwnerAsyncResult.cs
- Style.cs
- SoapHelper.cs
- Vector.cs
- ADMembershipProvider.cs
- InOutArgument.cs
- TextEditorContextMenu.cs
- ItemCheckedEvent.cs
- PathNode.cs
- PreviewControlDesigner.cs
- XPathException.cs
- XmlArrayItemAttribute.cs
- ProfileGroupSettingsCollection.cs
- UnmanagedMemoryStream.cs
- ExpressionTextBox.xaml.cs
- UIElementParagraph.cs
- __Error.cs
- DataRelationPropertyDescriptor.cs
- ImageButton.cs
- ResourcesChangeInfo.cs
- AttachedPropertiesService.cs
- SafePointer.cs
- PageDeviceFont.cs