Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2PropertyBuilderUITypeEditor.cs / 1 / COM2PropertyBuilderUITypeEditor.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.ComponentModel.Com2Interop { using Microsoft.Win32; using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; using System.Drawing; using System.Drawing.Design; using System.Runtime.InteropServices; using System.Windows.Forms.Design; using System.Globalization; ////// /// internal class Com2PropertyBuilderUITypeEditor : Com2ExtendedUITypeEditor { private Com2PropertyDescriptor propDesc; string guidString; int bldrType; public Com2PropertyBuilderUITypeEditor(Com2PropertyDescriptor pd, string guidString, int type, UITypeEditor baseEditor) : base(baseEditor) { propDesc = pd; this.guidString = guidString; this.bldrType = type; } ////// /// Takes the value returned from valueAccess.getValue() and modifies or replaces /// the value, passing the result into valueAccess.setValue(). This is where /// an editor can launch a modal dialog or create a drop down editor to allow /// the user to modify the value. Host assistance in presenting UI to the user /// can be found through the valueAccess.getService function. /// public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IntPtr parentHandle = (IntPtr)UnsafeNativeMethods.GetFocus(); IUIService uiSvc = (IUIService)provider.GetService(typeof(IUIService)); if (uiSvc != null) { IWin32Window parent = uiSvc.GetDialogOwnerWindow(); if (parent != null) { parentHandle = parent.Handle; } } bool useValue = false; //VARIANT pValue = null; object pValue = value; try{ object obj = propDesc.TargetObject; if (obj is ICustomTypeDescriptor) { obj = ((ICustomTypeDescriptor)obj).GetPropertyOwner(propDesc); } Debug.Assert(obj is NativeMethods.IProvidePropertyBuilder, "object is not IProvidePropertyBuilder"); NativeMethods.IProvidePropertyBuilder propBuilder = (NativeMethods.IProvidePropertyBuilder)obj; if (NativeMethods.Failed(propBuilder.ExecuteBuilder(propDesc.DISPID, guidString, null, new HandleRef(null, parentHandle), ref pValue, ref useValue))){ useValue = false; } }catch(ExternalException ex) { Debug.Fail("Failed to show property frame: " + ex.ErrorCode.ToString(CultureInfo.InvariantCulture)); } if (useValue && (bldrType & _CTLBLDTYPE.CTLBLDTYPE_FEDITSOBJDIRECTLY) == 0){ return pValue;//pValue.ToVariant(); } return value; } ////// /// Retrieves the editing style of the Edit method. If the method /// is not supported, this will return None. /// public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } } } // 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 Microsoft.Win32; using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; using System.Drawing; using System.Drawing.Design; using System.Runtime.InteropServices; using System.Windows.Forms.Design; using System.Globalization; ////// /// internal class Com2PropertyBuilderUITypeEditor : Com2ExtendedUITypeEditor { private Com2PropertyDescriptor propDesc; string guidString; int bldrType; public Com2PropertyBuilderUITypeEditor(Com2PropertyDescriptor pd, string guidString, int type, UITypeEditor baseEditor) : base(baseEditor) { propDesc = pd; this.guidString = guidString; this.bldrType = type; } ////// /// Takes the value returned from valueAccess.getValue() and modifies or replaces /// the value, passing the result into valueAccess.setValue(). This is where /// an editor can launch a modal dialog or create a drop down editor to allow /// the user to modify the value. Host assistance in presenting UI to the user /// can be found through the valueAccess.getService function. /// public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IntPtr parentHandle = (IntPtr)UnsafeNativeMethods.GetFocus(); IUIService uiSvc = (IUIService)provider.GetService(typeof(IUIService)); if (uiSvc != null) { IWin32Window parent = uiSvc.GetDialogOwnerWindow(); if (parent != null) { parentHandle = parent.Handle; } } bool useValue = false; //VARIANT pValue = null; object pValue = value; try{ object obj = propDesc.TargetObject; if (obj is ICustomTypeDescriptor) { obj = ((ICustomTypeDescriptor)obj).GetPropertyOwner(propDesc); } Debug.Assert(obj is NativeMethods.IProvidePropertyBuilder, "object is not IProvidePropertyBuilder"); NativeMethods.IProvidePropertyBuilder propBuilder = (NativeMethods.IProvidePropertyBuilder)obj; if (NativeMethods.Failed(propBuilder.ExecuteBuilder(propDesc.DISPID, guidString, null, new HandleRef(null, parentHandle), ref pValue, ref useValue))){ useValue = false; } }catch(ExternalException ex) { Debug.Fail("Failed to show property frame: " + ex.ErrorCode.ToString(CultureInfo.InvariantCulture)); } if (useValue && (bldrType & _CTLBLDTYPE.CTLBLDTYPE_FEDITSOBJDIRECTLY) == 0){ return pValue;//pValue.ToVariant(); } return value; } ////// /// Retrieves the editing style of the Edit method. If the method /// is not supported, this will return None. /// public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } } } // 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
- HtmlTable.cs
- CanExecuteRoutedEventArgs.cs
- CancelEventArgs.cs
- SelectedCellsCollection.cs
- IdleTimeoutMonitor.cs
- BoundConstants.cs
- AlternateView.cs
- LinqDataSourceInsertEventArgs.cs
- ToolboxBitmapAttribute.cs
- SqlDataSourceCommandEventArgs.cs
- EnumMemberAttribute.cs
- MaskDescriptors.cs
- UTF8Encoding.cs
- ConsumerConnectionPointCollection.cs
- Int32Storage.cs
- UIElement.cs
- NullableDecimalMinMaxAggregationOperator.cs
- DataGridViewTextBoxCell.cs
- ObjectDataSourceSelectingEventArgs.cs
- IsolatedStorageException.cs
- TableRow.cs
- TimerEventSubscription.cs
- ResXFileRef.cs
- FormsIdentity.cs
- WebPartCollection.cs
- KoreanCalendar.cs
- EntityParameterCollection.cs
- UriWriter.cs
- TextSelectionHighlightLayer.cs
- ReaderContextStackData.cs
- XmlCompatibilityReader.cs
- autovalidator.cs
- SHA512.cs
- UpdateManifestForBrowserApplication.cs
- AtomMaterializer.cs
- EntitySetDataBindingList.cs
- GroupJoinQueryOperator.cs
- CodeCompiler.cs
- CellPartitioner.cs
- TileBrush.cs
- Italic.cs
- DoubleAnimationBase.cs
- ArgumentNullException.cs
- Splitter.cs
- MessageQueueCriteria.cs
- DocumentGrid.cs
- ContainerParagraph.cs
- SemaphoreSecurity.cs
- Compensate.cs
- UserPersonalizationStateInfo.cs
- SerTrace.cs
- Identifier.cs
- CallSiteBinder.cs
- PrefixHandle.cs
- ProfilePropertyNameValidator.cs
- OLEDB_Enum.cs
- UpdateEventArgs.cs
- TraceFilter.cs
- ResourceIDHelper.cs
- FileCodeGroup.cs
- UserPreferenceChangedEventArgs.cs
- DesignerToolboxInfo.cs
- TraceLevelStore.cs
- ViewSimplifier.cs
- AssemblyAttributes.cs
- DataKeyArray.cs
- ScrollEvent.cs
- AccessKeyManager.cs
- MergablePropertyAttribute.cs
- ScriptReference.cs
- EventManager.cs
- XmlSchemaSimpleContentExtension.cs
- ResponseStream.cs
- ColumnMapVisitor.cs
- ErrorWebPart.cs
- SolidColorBrush.cs
- CompilerGeneratedAttribute.cs
- PersonalizationStateQuery.cs
- CodePrimitiveExpression.cs
- UnmanagedMarshal.cs
- NetMsmqSecurityElement.cs
- FileVersion.cs
- MarkupObject.cs
- CreateUserErrorEventArgs.cs
- DesignerProperties.cs
- SeekStoryboard.cs
- SqlFunctionAttribute.cs
- ImageButton.cs
- PropertyAccessVisitor.cs
- SqlLiftIndependentRowExpressions.cs
- MsmqOutputChannel.cs
- UnauthorizedWebPart.cs
- HiddenFieldPageStatePersister.cs
- CellConstantDomain.cs
- XsdSchemaFileEditor.cs
- OrderedDictionary.cs
- RC2CryptoServiceProvider.cs
- PerformanceCounterManager.cs
- SchemaSetCompiler.cs
- BypassElementCollection.cs