Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2AboutBoxPropertyDescriptor.cs / 1305376 / COM2AboutBoxPropertyDescriptor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.ComponentModel.Com2Interop {
using System.Runtime.Serialization.Formatters;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System;
using System.ComponentModel.Design;
using Microsoft.Win32;
using System.Collections;
using System.Drawing.Design;
internal class Com2AboutBoxPropertyDescriptor : Com2PropertyDescriptor {
private TypeConverter converter;
private UITypeEditor editor;
public Com2AboutBoxPropertyDescriptor() : base(NativeMethods.ActiveX.DISPID_ABOUTBOX, "About", new Attribute[]{new DispIdAttribute(NativeMethods.ActiveX.DISPID_ABOUTBOX),
DesignerSerializationVisibilityAttribute.Hidden,
new DescriptionAttribute(SR.GetString(SR.AboutBoxDesc)),
new ParenthesizePropertyNameAttribute(true)}, true, typeof(string), null, false) {
}
///
///
/// Retrieves the type of the component this PropertyDescriptor is bound to.
///
public override Type ComponentType {
get {
return typeof(UnsafeNativeMethods.IDispatch);
}
}
///
///
/// Retrieves the type converter for this property.
///
public override TypeConverter Converter {
get {
if (converter == null) {
converter = new TypeConverter();
}
return converter;
}
}
///
///
/// Indicates whether this property is read only.
///
public override bool IsReadOnly {
get {
return true;
}
}
///
///
/// Retrieves the type of the property.
///
public override Type PropertyType {
get {
return typeof(string);
}
}
///
///
/// Indicates whether reset will change the value of the component. If there
/// is a DefaultValueAttribute, then this will return true if getValue returns
/// something different than the default value. If there is a reset method and
/// a shouldPersist method, this will return what shouldPersist returns.
/// If there is just a reset method, this always returns true. If none of these
/// cases apply, this returns false.
///
public override bool CanResetValue(object component) {
return false;
}
///
///
/// Retrieves an editor of the requested type.
///
public override object GetEditor(Type editorBaseType) {
if (editorBaseType == typeof(UITypeEditor)) {
if (editor == null) {
editor = new AboutBoxUITypeEditor();
}
}
return editor;
}
///
///
/// Retrieves the current value of the property on component,
/// invoking the getXXX method. An exception in the getXXX
/// method will pass through.
///
public override object GetValue(object component) {
return "";
}
///
///
/// Will reset the default value for this property on the component. If
/// there was a default value passed in as a DefaultValueAttribute, that
/// value will be set as the value of the property on the component. If
/// there was no default value passed in, a ResetXXX method will be looked
/// for. If one is found, it will be invoked. If one is not found, this
/// is a nop.
///
public override void ResetValue(object component){
}
///
///
/// This will set value to be the new value of this property on the
/// component by invoking the setXXX method on the component. If the
/// value specified is invalid, the component should throw an exception
/// which will be passed up. The component designer should design the
/// property so that getXXX following a setXXX should return the value
/// passed in if no exception was thrown in the setXXX call.
///
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
public override void SetValue(object component, object value) {
throw new ArgumentException();
}
///
///
/// Indicates whether the value of this property needs to be persisted. In
/// other words, it indicates whether the state of the property is distinct
/// from when the component is first instantiated. If there is a default
/// value specified in this PropertyDescriptor, it will be compared against the
/// property's current value to determine this. If there is't, the
/// shouldPersistXXX method is looked for and invoked if found. If both
/// these routes fail, true will be returned.
///
/// If this returns false, a tool should not persist this property's value.
///
public override bool ShouldSerializeValue(object component) {
return false;
}
public class AboutBoxUITypeEditor : UITypeEditor {
///
///
/// Edits the given object value using the editor style provided by
/// GetEditorStyle. A service provider is provided so that any
/// required editing services can be obtained.
///
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
object component = context.Instance;
if (Marshal.IsComObject(component) && component is UnsafeNativeMethods.IDispatch) {
UnsafeNativeMethods.IDispatch pDisp = (UnsafeNativeMethods.IDispatch)component;
NativeMethods.tagEXCEPINFO pExcepInfo = new NativeMethods.tagEXCEPINFO();
Guid g = Guid.Empty;
int hr = pDisp.Invoke(NativeMethods.ActiveX.DISPID_ABOUTBOX,
ref g,
SafeNativeMethods.GetThreadLCID(),
NativeMethods.DISPATCH_METHOD,
new NativeMethods.tagDISPPARAMS(),
null,
pExcepInfo, null);
Debug.Assert(NativeMethods.Succeeded(hr), "Failed to launch about box.");
}
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 System.Runtime.Serialization.Formatters;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System;
using System.ComponentModel.Design;
using Microsoft.Win32;
using System.Collections;
using System.Drawing.Design;
internal class Com2AboutBoxPropertyDescriptor : Com2PropertyDescriptor {
private TypeConverter converter;
private UITypeEditor editor;
public Com2AboutBoxPropertyDescriptor() : base(NativeMethods.ActiveX.DISPID_ABOUTBOX, "About", new Attribute[]{new DispIdAttribute(NativeMethods.ActiveX.DISPID_ABOUTBOX),
DesignerSerializationVisibilityAttribute.Hidden,
new DescriptionAttribute(SR.GetString(SR.AboutBoxDesc)),
new ParenthesizePropertyNameAttribute(true)}, true, typeof(string), null, false) {
}
///
///
/// Retrieves the type of the component this PropertyDescriptor is bound to.
///
public override Type ComponentType {
get {
return typeof(UnsafeNativeMethods.IDispatch);
}
}
///
///
/// Retrieves the type converter for this property.
///
public override TypeConverter Converter {
get {
if (converter == null) {
converter = new TypeConverter();
}
return converter;
}
}
///
///
/// Indicates whether this property is read only.
///
public override bool IsReadOnly {
get {
return true;
}
}
///
///
/// Retrieves the type of the property.
///
public override Type PropertyType {
get {
return typeof(string);
}
}
///
///
/// Indicates whether reset will change the value of the component. If there
/// is a DefaultValueAttribute, then this will return true if getValue returns
/// something different than the default value. If there is a reset method and
/// a shouldPersist method, this will return what shouldPersist returns.
/// If there is just a reset method, this always returns true. If none of these
/// cases apply, this returns false.
///
public override bool CanResetValue(object component) {
return false;
}
///
///
/// Retrieves an editor of the requested type.
///
public override object GetEditor(Type editorBaseType) {
if (editorBaseType == typeof(UITypeEditor)) {
if (editor == null) {
editor = new AboutBoxUITypeEditor();
}
}
return editor;
}
///
///
/// Retrieves the current value of the property on component,
/// invoking the getXXX method. An exception in the getXXX
/// method will pass through.
///
public override object GetValue(object component) {
return "";
}
///
///
/// Will reset the default value for this property on the component. If
/// there was a default value passed in as a DefaultValueAttribute, that
/// value will be set as the value of the property on the component. If
/// there was no default value passed in, a ResetXXX method will be looked
/// for. If one is found, it will be invoked. If one is not found, this
/// is a nop.
///
public override void ResetValue(object component){
}
///
///
/// This will set value to be the new value of this property on the
/// component by invoking the setXXX method on the component. If the
/// value specified is invalid, the component should throw an exception
/// which will be passed up. The component designer should design the
/// property so that getXXX following a setXXX should return the value
/// passed in if no exception was thrown in the setXXX call.
///
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
public override void SetValue(object component, object value) {
throw new ArgumentException();
}
///
///
/// Indicates whether the value of this property needs to be persisted. In
/// other words, it indicates whether the state of the property is distinct
/// from when the component is first instantiated. If there is a default
/// value specified in this PropertyDescriptor, it will be compared against the
/// property's current value to determine this. If there is't, the
/// shouldPersistXXX method is looked for and invoked if found. If both
/// these routes fail, true will be returned.
///
/// If this returns false, a tool should not persist this property's value.
///
public override bool ShouldSerializeValue(object component) {
return false;
}
public class AboutBoxUITypeEditor : UITypeEditor {
///
///
/// Edits the given object value using the editor style provided by
/// GetEditorStyle. A service provider is provided so that any
/// required editing services can be obtained.
///
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
object component = context.Instance;
if (Marshal.IsComObject(component) && component is UnsafeNativeMethods.IDispatch) {
UnsafeNativeMethods.IDispatch pDisp = (UnsafeNativeMethods.IDispatch)component;
NativeMethods.tagEXCEPINFO pExcepInfo = new NativeMethods.tagEXCEPINFO();
Guid g = Guid.Empty;
int hr = pDisp.Invoke(NativeMethods.ActiveX.DISPID_ABOUTBOX,
ref g,
SafeNativeMethods.GetThreadLCID(),
NativeMethods.DISPATCH_METHOD,
new NativeMethods.tagDISPPARAMS(),
null,
pExcepInfo, null);
Debug.Assert(NativeMethods.Succeeded(hr), "Failed to launch about box.");
}
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
- FragmentQueryProcessor.cs
- CompilerGlobalScopeAttribute.cs
- PassportAuthenticationEventArgs.cs
- UnicastIPAddressInformationCollection.cs
- ImmComposition.cs
- Facet.cs
- TiffBitmapDecoder.cs
- RequiredFieldValidator.cs
- EncoderNLS.cs
- SR.cs
- InlinedLocationReference.cs
- RequestQueue.cs
- PersonalizablePropertyEntry.cs
- TdsParameterSetter.cs
- FocusManager.cs
- GroupBox.cs
- WindowsGraphics.cs
- UIElementPropertyUndoUnit.cs
- HtmlTextArea.cs
- SeparatorAutomationPeer.cs
- QilInvoke.cs
- LoginView.cs
- ConstructorNeedsTagAttribute.cs
- UriTemplateTable.cs
- SimpleTableProvider.cs
- DataListCommandEventArgs.cs
- PlanCompiler.cs
- XmlUrlResolver.cs
- TraceUtility.cs
- UnmanagedHandle.cs
- GridViewRowPresenterBase.cs
- MD5CryptoServiceProvider.cs
- DbConnectionPoolOptions.cs
- DbSource.cs
- UserControlParser.cs
- AnimationClock.cs
- CriticalHandle.cs
- BitmapEffectInputConnector.cs
- EventSourceCreationData.cs
- ComNativeDescriptor.cs
- DivideByZeroException.cs
- CompositeControl.cs
- ISessionStateStore.cs
- Base64Decoder.cs
- AutomationElement.cs
- TokenCreationException.cs
- RelatedView.cs
- DecoderBestFitFallback.cs
- RootProjectionNode.cs
- TextEditorThreadLocalStore.cs
- ChtmlTextWriter.cs
- WebPartExportVerb.cs
- CopyNamespacesAction.cs
- ProcessModelInfo.cs
- CompoundFileReference.cs
- PreProcessor.cs
- CodeDomLoader.cs
- WebConfigurationHost.cs
- EntityDataSourceDesignerHelper.cs
- Vector3DValueSerializer.cs
- EndpointIdentityConverter.cs
- DataTableExtensions.cs
- SendKeys.cs
- ModelUIElement3D.cs
- Win32.cs
- COAUTHINFO.cs
- TemplatingOptionsDialog.cs
- DesignerActionMethodItem.cs
- SQLInt16.cs
- ImageMetadata.cs
- RemoteWebConfigurationHost.cs
- AccessText.cs
- Roles.cs
- IOException.cs
- TextEvent.cs
- AssemblyResourceLoader.cs
- TextReader.cs
- ObjectReaderCompiler.cs
- Pts.cs
- CompiledIdentityConstraint.cs
- EventLogPermissionEntry.cs
- DiscoveryRequestHandler.cs
- SmiGettersStream.cs
- StorageRoot.cs
- WebServicesDescriptionAttribute.cs
- WebConfigurationHostFileChange.cs
- RuntimeVariablesExpression.cs
- NativeCompoundFileAPIs.cs
- RightsManagementEncryptedStream.cs
- EnumerableCollectionView.cs
- SHA512.cs
- CodeTypeReferenceCollection.cs
- ListBox.cs
- EventProviderClassic.cs
- RelationshipEndCollection.cs
- Util.cs
- ReadOnlyAttribute.cs
- ContentTextAutomationPeer.cs
- XmlSignatureProperties.cs
- XmlImplementation.cs