Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- AnimatedTypeHelpers.cs
- CommandID.cs
- DBSchemaTable.cs
- WindowsMenu.cs
- FlowDocument.cs
- ProviderSettings.cs
- StringUtil.cs
- ModelChangedEventArgsImpl.cs
- KeyEvent.cs
- AVElementHelper.cs
- QueryHandler.cs
- RequestFactory.cs
- PtsHost.cs
- App.cs
- DataSysAttribute.cs
- TabControlEvent.cs
- DeferredSelectedIndexReference.cs
- DbConnectionFactory.cs
- baseaxisquery.cs
- TreeBuilderXamlTranslator.cs
- SamlAuthenticationClaimResource.cs
- RectIndependentAnimationStorage.cs
- XmlSchemaGroup.cs
- ProfileBuildProvider.cs
- TabPanel.cs
- ExtentCqlBlock.cs
- EndpointInstanceProvider.cs
- TemplateBuilder.cs
- ConsoleKeyInfo.cs
- OdbcDataReader.cs
- TextElementEnumerator.cs
- AttributeCollection.cs
- XPathSingletonIterator.cs
- SqlReorderer.cs
- SmiMetaDataProperty.cs
- TextBreakpoint.cs
- TemplateColumn.cs
- CfgSemanticTag.cs
- ObjectDataSourceView.cs
- WindowProviderWrapper.cs
- MimeFormReflector.cs
- FramingFormat.cs
- DataColumnChangeEvent.cs
- Lease.cs
- WebResponse.cs
- HttpCookieCollection.cs
- DynamicRendererThreadManager.cs
- HtmlTable.cs
- BreadCrumbTextConverter.cs
- Rotation3D.cs
- Converter.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- StateMachine.cs
- StrictAndMessageFilter.cs
- InfoCardClaimCollection.cs
- TopClause.cs
- InvalidateEvent.cs
- PinnedBufferMemoryStream.cs
- ProfileService.cs
- CheckBox.cs
- UnhandledExceptionEventArgs.cs
- CircleHotSpot.cs
- Int32CollectionConverter.cs
- cache.cs
- GridViewRowCollection.cs
- CornerRadiusConverter.cs
- CurrencyWrapper.cs
- ProviderManager.cs
- METAHEADER.cs
- SinglePageViewer.cs
- ToolStripPanelDesigner.cs
- DelayedRegex.cs
- StreamGeometry.cs
- DataGridViewCellEventArgs.cs
- TaiwanLunisolarCalendar.cs
- WorkflowTerminatedException.cs
- CategoryNameCollection.cs
- WindowsRegion.cs
- XPathConvert.cs
- XmlSignificantWhitespace.cs
- SQLInt64Storage.cs
- SpellerStatusTable.cs
- DataSysAttribute.cs
- messageonlyhwndwrapper.cs
- MaskedTextBox.cs
- ImageKeyConverter.cs
- ToolStripGripRenderEventArgs.cs
- ActivityDesignerResources.cs
- ExplicitDiscriminatorMap.cs
- KnownTypeHelper.cs
- MemberHolder.cs
- MemoryRecordBuffer.cs
- RuntimeHandles.cs
- configsystem.cs
- RichTextBoxAutomationPeer.cs
- DataServiceRequestOfT.cs
- Typeface.cs
- Utility.cs
- ValueType.cs
- SerializationSectionGroup.cs