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
- AppDomainFactory.cs
- AdapterDictionary.cs
- ResourcePool.cs
- BezierSegment.cs
- TableNameAttribute.cs
- OrthographicCamera.cs
- HeaderCollection.cs
- BitConverter.cs
- SqlReferenceCollection.cs
- TableStyle.cs
- TextShapeableCharacters.cs
- IgnoreSection.cs
- CompositeDataBoundControl.cs
- AssemblyContextControlItem.cs
- SerializationHelper.cs
- Nullable.cs
- InstanceCreationEditor.cs
- BitVec.cs
- OleDbMetaDataFactory.cs
- CodeAttributeArgument.cs
- SafeNativeMethodsOther.cs
- TextEncodedRawTextWriter.cs
- SafeRightsManagementSessionHandle.cs
- BasicExpressionVisitor.cs
- CursorConverter.cs
- SimpleApplicationHost.cs
- PageBuildProvider.cs
- EnumMember.cs
- PrePrepareMethodAttribute.cs
- Globals.cs
- ClickablePoint.cs
- SchemaCollectionPreprocessor.cs
- XmlEncodedRawTextWriter.cs
- ValueUtilsSmi.cs
- Stacktrace.cs
- DrawingVisual.cs
- NavigationPropertySingletonExpression.cs
- QilSortKey.cs
- ConfigurationProviderException.cs
- PreProcessInputEventArgs.cs
- PolicyConversionContext.cs
- log.cs
- CustomExpressionEventArgs.cs
- TemplateBamlRecordReader.cs
- ControlPaint.cs
- TableCellCollection.cs
- DoubleSumAggregationOperator.cs
- LinqDataSource.cs
- LinqDataSourceContextData.cs
- CompareInfo.cs
- TextViewElement.cs
- CipherData.cs
- BamlTreeMap.cs
- ViewKeyConstraint.cs
- WeakReference.cs
- _NtlmClient.cs
- MdiWindowListItemConverter.cs
- XmlEntityReference.cs
- SemanticBasicElement.cs
- Root.cs
- NativeObjectSecurity.cs
- ReadOnlyCollectionBase.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- JournalEntryListConverter.cs
- TreeNodeBinding.cs
- ValidatingReaderNodeData.cs
- XmlNode.cs
- ConditionedDesigner.cs
- SelectionHighlightInfo.cs
- PropertyConverter.cs
- VisualStyleElement.cs
- RadioButtonList.cs
- Pen.cs
- DescendantBaseQuery.cs
- BamlReader.cs
- AnonymousIdentificationSection.cs
- _BasicClient.cs
- ConnectionManagementElementCollection.cs
- PerformanceCounterPermissionAttribute.cs
- ResourceKey.cs
- GenericsNotImplementedException.cs
- AddingNewEventArgs.cs
- FunctionMappingTranslator.cs
- SecurityHelper.cs
- EmptyReadOnlyDictionaryInternal.cs
- SchemaImporterExtension.cs
- ToolbarAUtomationPeer.cs
- VarInfo.cs
- ProviderSettings.cs
- XmlDocumentSchema.cs
- ChangeDirector.cs
- EditCommandColumn.cs
- WCFBuildProvider.cs
- CodeExporter.cs
- oledbmetadatacolumnnames.cs
- ChildTable.cs
- cookie.cs
- UriSection.cs
- NotCondition.cs
- IndexedString.cs