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
- StringValidator.cs
- CookieParameter.cs
- FontConverter.cs
- StateElementCollection.cs
- EncodedStreamFactory.cs
- RegexCharClass.cs
- PlacementWorkspace.cs
- PropertyEmitter.cs
- ADMembershipProvider.cs
- CatalogZoneDesigner.cs
- ConsumerConnectionPointCollection.cs
- FileDialog_Vista_Interop.cs
- ApplicationHost.cs
- EntryPointNotFoundException.cs
- ListParagraph.cs
- ControlUtil.cs
- DnsPermission.cs
- BinaryObjectReader.cs
- dsa.cs
- NetworkInformationException.cs
- InvalidAsynchronousStateException.cs
- SchemaSetCompiler.cs
- SqlMethodCallConverter.cs
- BamlRecordHelper.cs
- XsltArgumentList.cs
- XmlFormatReaderGenerator.cs
- input.cs
- SoapTypeAttribute.cs
- IndexedGlyphRun.cs
- ExpressionBuilderContext.cs
- ComponentEditorForm.cs
- UInt16Storage.cs
- BinHexEncoder.cs
- MouseButton.cs
- PropertySourceInfo.cs
- BinaryFormatter.cs
- ConnectionManagementElementCollection.cs
- ColumnMap.cs
- CustomErrorsSection.cs
- LinqDataView.cs
- TaskFactory.cs
- VisualStyleInformation.cs
- DBDataPermission.cs
- TypefaceMetricsCache.cs
- WebDescriptionAttribute.cs
- DataGridViewComboBoxCell.cs
- EllipseGeometry.cs
- FontInfo.cs
- DataObjectSettingDataEventArgs.cs
- FormsAuthenticationTicket.cs
- SendMailErrorEventArgs.cs
- SelectionHighlightInfo.cs
- WindowsToolbarItemAsMenuItem.cs
- ByteConverter.cs
- EndpointIdentity.cs
- Util.cs
- DbProviderSpecificTypePropertyAttribute.cs
- SortDescriptionCollection.cs
- CompilerErrorCollection.cs
- EntityDataSourceQueryBuilder.cs
- PixelFormats.cs
- QilGenerator.cs
- XPathDocumentBuilder.cs
- FillBehavior.cs
- QuaternionAnimation.cs
- AddDataControlFieldDialog.cs
- DetailsViewUpdateEventArgs.cs
- Annotation.cs
- RotationValidation.cs
- CodeAccessSecurityEngine.cs
- OleDbInfoMessageEvent.cs
- HtmlGenericControl.cs
- FormsAuthenticationCredentials.cs
- Panel.cs
- Socket.cs
- CapabilitiesState.cs
- XmlTypeAttribute.cs
- DetailsViewModeEventArgs.cs
- FilterException.cs
- TdsParserHelperClasses.cs
- FormViewDeleteEventArgs.cs
- MethodBody.cs
- WindowsAuthenticationEventArgs.cs
- PopupRoot.cs
- ScriptingWebServicesSectionGroup.cs
- MemberCollection.cs
- ColumnHeaderConverter.cs
- SessionPageStatePersister.cs
- InternalBase.cs
- CookieParameter.cs
- Int32Collection.cs
- PackageProperties.cs
- ExecutionContext.cs
- XmlSerializationReader.cs
- XmlAttributeCollection.cs
- Symbol.cs
- MachineKeySection.cs
- ProxyElement.cs
- DelegatedStream.cs
- UnsafeNativeMethods.cs