Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2PropertyBuilderUITypeEditor.cs / 1305376 / 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
- XmlBinaryReaderSession.cs
- ForwardPositionQuery.cs
- UIElement.cs
- LinkedDataMemberFieldEditor.cs
- FormViewUpdateEventArgs.cs
- TimerElapsedEvenArgs.cs
- ButtonChrome.cs
- _ScatterGatherBuffers.cs
- ServiceModelConfigurationSectionGroup.cs
- LinkLabelLinkClickedEvent.cs
- UserControl.cs
- WmlValidationSummaryAdapter.cs
- QilTernary.cs
- ProtocolsConfigurationHandler.cs
- TCPClient.cs
- String.cs
- CommonObjectSecurity.cs
- GenericXmlSecurityToken.cs
- NativeMethodsOther.cs
- IfAction.cs
- TextBox.cs
- DBCommand.cs
- PropertyValueChangedEvent.cs
- CodeSubDirectory.cs
- LinqDataSourceValidationException.cs
- ProgressBar.cs
- PixelShader.cs
- StylusDevice.cs
- ToolStripPanel.cs
- SecurityTokenRequirement.cs
- OleDbPropertySetGuid.cs
- SymbolEqualComparer.cs
- entitydatasourceentitysetnameconverter.cs
- DirectoryNotFoundException.cs
- Msec.cs
- SecurityManager.cs
- FlowDocument.cs
- VisualBasic.cs
- OSFeature.cs
- Pkcs9Attribute.cs
- PrinterSettings.cs
- DataServiceQuery.cs
- InheritanceRules.cs
- DesignBindingValueUIHandler.cs
- ObjectNavigationPropertyMapping.cs
- PropertyChangeTracker.cs
- HGlobalSafeHandle.cs
- DropDownHolder.cs
- VersionedStreamOwner.cs
- MetadataUtilsSmi.cs
- ResourceExpressionBuilder.cs
- UserNameSecurityToken.cs
- BitmapEffectrendercontext.cs
- HandlerFactoryCache.cs
- FileChangeNotifier.cs
- DesignerDataStoredProcedure.cs
- SchemaImporterExtensionsSection.cs
- TableItemPattern.cs
- DependencyObjectPropertyDescriptor.cs
- ToolStripItemImageRenderEventArgs.cs
- MobileControlBuilder.cs
- DesignerSerializationManager.cs
- loginstatus.cs
- Filter.cs
- RemotingSurrogateSelector.cs
- Operand.cs
- MenuItemStyle.cs
- ArrayExtension.cs
- DateRangeEvent.cs
- PolyLineSegmentFigureLogic.cs
- ApplicationActivator.cs
- WebServiceParameterData.cs
- AddInEnvironment.cs
- XmlWriterTraceListener.cs
- IndexedEnumerable.cs
- XmlSchemaIdentityConstraint.cs
- TemplateXamlParser.cs
- BrowserDefinitionCollection.cs
- WorkflowRuntimeServiceElement.cs
- InputLanguageCollection.cs
- SafeEventLogWriteHandle.cs
- TargetInvocationException.cs
- IISUnsafeMethods.cs
- XsdCachingReader.cs
- configsystem.cs
- DateTimeAutomationPeer.cs
- DataGridViewCellValueEventArgs.cs
- SafeHandles.cs
- RowParagraph.cs
- RSAPKCS1KeyExchangeFormatter.cs
- TypeElement.cs
- Cursors.cs
- ApplicationActivator.cs
- EncoderNLS.cs
- DynamicEntity.cs
- DeviceFilterEditorDialog.cs
- XmlCharCheckingReader.cs
- DynamicExpression.cs
- SHA512Managed.cs
- Model3DGroup.cs