Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / ReadWriteControlDesigner.cs / 1 / ReadWriteControlDesigner.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.Design { using Microsoft.Win32; using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Design; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.Web.UI.WebControls; ////// /// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] [Obsolete("The recommended alternative is ContainerControlDesigner because it uses an EditableDesignerRegion for editing the content. Designer regions allow for better control of the content being edited. http://go.microsoft.com/fwlink/?linkid=14202")] public class ReadWriteControlDesigner : ControlDesigner { ///Provides a base designer class for all read-write server controls. ////// /// public ReadWriteControlDesigner() { ReadOnlyInternal = false; } ////// Initializes an instance of the ///class. /// /// public override string GetDesignTimeHtml() { return CreatePlaceHolderDesignTimeHtml(); } /// /// /// public override void OnComponentChanged(object sender, ComponentChangedEventArgs ce) { // Delegate to the base class implementation first! base.OnComponentChanged(sender, ce); if (IsIgnoringComponentChanges) { return; } if (!IsWebControl || (DesignTimeElementInternal == null)) { return; } MemberDescriptor member = ce.Member; object newValue = ce.NewValue; // HACK: you guys need to figure out a less hacky way then looking // for internal types... Type t = Type.GetType("System.ComponentModel.ReflectPropertyDescriptor, " + AssemblyRef.System); if (member != null && member.GetType() == t) { PropertyDescriptor propDesc = (PropertyDescriptor)member; if (member.Name.Equals("Font")) { WebControl control = (WebControl)Component; newValue = control.Font.Name; MapPropertyToStyle("Font.Name", newValue); newValue = control.Font.Size; MapPropertyToStyle("Font.Size", newValue); newValue = control.Font.Bold; MapPropertyToStyle("Font.Bold", newValue); newValue = control.Font.Italic; MapPropertyToStyle("Font.Italic", newValue); newValue = control.Font.Underline; MapPropertyToStyle("Font.Underline", newValue); newValue = control.Font.Strikeout; MapPropertyToStyle("Font.Strikeout", newValue); newValue = control.Font.Overline; MapPropertyToStyle("Font.Overline", newValue); } else if (newValue != null) { if (propDesc.PropertyType == typeof(Color)) { newValue = System.Drawing.ColorTranslator.ToHtml((System.Drawing.Color)newValue); } MapPropertyToStyle(propDesc.Name, newValue); } } } ////// Delegate to handle component changed event. /// ///protected virtual void MapPropertyToStyle(string propName, object varPropValue) { if (BehaviorInternal == null) return; Debug.Assert(propName != null && propName.Length != 0, "Invalid property name passed in!"); Debug.Assert(varPropValue != null, "Invalid property value passed in!"); if (propName == null || varPropValue == null) { return; } try { if (propName.Equals("BackColor")) { BehaviorInternal.SetStyleAttribute("backgroundColor", true /* designTimeOnly */, varPropValue, true /* ignoreCase */); } else if (propName.Equals("ForeColor")) { BehaviorInternal.SetStyleAttribute("color", true, varPropValue, true); } else if (propName.Equals("BorderWidth")) { string strPropValue = Convert.ToString(varPropValue, CultureInfo.InvariantCulture); BehaviorInternal.SetStyleAttribute("borderWidth", true, strPropValue, true); } else if (propName.Equals("BorderStyle")) { string strPropValue; if ((BorderStyle)varPropValue == BorderStyle.NotSet) { strPropValue = String.Empty; } else { strPropValue = Enum.Format(typeof(BorderStyle), (BorderStyle)varPropValue, "G"); } BehaviorInternal.SetStyleAttribute("borderStyle", true, strPropValue, true); } else if (propName.Equals("BorderColor")) { BehaviorInternal.SetStyleAttribute("borderColor", true, Convert.ToString(varPropValue, CultureInfo.InvariantCulture), true); } else if (propName.Equals("Height")) { BehaviorInternal.SetStyleAttribute("height", true, Convert.ToString(varPropValue, CultureInfo.InvariantCulture), true); } else if (propName.Equals("Width")) { BehaviorInternal.SetStyleAttribute("width", true, Convert.ToString(varPropValue, CultureInfo.InvariantCulture), true); } else if (propName.Equals("Font.Name")) { BehaviorInternal.SetStyleAttribute("fontFamily", true, Convert.ToString(varPropValue, CultureInfo.InvariantCulture), true); } else if (propName.Equals("Font.Size")) { BehaviorInternal.SetStyleAttribute("fontSize", true, Convert.ToString(varPropValue, CultureInfo.InvariantCulture), true); } else if (propName.Equals("Font.Bold")) { string styleValue; if ((bool)varPropValue) { styleValue = "bold"; } else { styleValue = "normal"; } BehaviorInternal.SetStyleAttribute("fontWeight", true, styleValue, true); } else if (propName.Equals("Font.Italic")) { string styleValue; if ((bool)varPropValue) { styleValue = "italic"; } else { styleValue = "normal"; } BehaviorInternal.SetStyleAttribute("fontStyle", true, styleValue, true); } else if (propName.Equals("Font.Underline")) { string styleValue = (string)BehaviorInternal.GetStyleAttribute("textDecoration", true, true); if ((bool)varPropValue) { if (styleValue == null) { styleValue = "underline"; } else if (styleValue.ToLower(CultureInfo.InvariantCulture).IndexOf("underline", StringComparison.Ordinal) < 0) { styleValue += " underline"; } BehaviorInternal.SetStyleAttribute("textDecoration", true, styleValue, true); } else if (styleValue != null) { int index = styleValue.ToLower(CultureInfo.InvariantCulture).IndexOf("underline", StringComparison.Ordinal); if (index >= 0) { string newStyleValue = styleValue.Substring(0, index); if (index + 9 < styleValue.Length) { newStyleValue = " " + styleValue.Substring(index + 9); } BehaviorInternal.SetStyleAttribute("textDecoration", true, newStyleValue, true); } } } else if (propName.Equals("Font.Strikeout")) { string styleValue = (string)BehaviorInternal.GetStyleAttribute("textDecoration", true, true); if ((bool)varPropValue) { if (styleValue == null) { styleValue = "line-through"; } else if (styleValue.ToLower(CultureInfo.InvariantCulture).IndexOf("line-through", StringComparison.Ordinal) < 0) { styleValue += " line-through"; } BehaviorInternal.SetStyleAttribute("textDecoration", true, styleValue, true); } else if (styleValue != null) { int index = styleValue.ToLower(CultureInfo.InvariantCulture).IndexOf("line-through", StringComparison.Ordinal); if (index >= 0) { string newStyleValue = styleValue.Substring(0, index); if (index + 12 < styleValue.Length) { newStyleValue = " " + styleValue.Substring(index + 12); } BehaviorInternal.SetStyleAttribute("textDecoration", true, newStyleValue, true); } } } else if (propName.Equals("Font.Overline")) { string styleValue = (string)BehaviorInternal.GetStyleAttribute("textDecoration", true, true); if ((bool)varPropValue) { if (styleValue == null) { styleValue = "overline"; } else if (styleValue.ToLower(CultureInfo.InvariantCulture).IndexOf("overline", StringComparison.Ordinal) < 0) { styleValue += " overline"; } BehaviorInternal.SetStyleAttribute("textDecoration", true, styleValue, true); } else if (styleValue != null) { int index = styleValue.ToLower(CultureInfo.InvariantCulture).IndexOf("overline", StringComparison.Ordinal); if (index >= 0) { string newStyleValue = styleValue.Substring(0, index); if (index + 8 < styleValue.Length) { newStyleValue = " " + styleValue.Substring(index + 8); } BehaviorInternal.SetStyleAttribute("textDecoration", true, newStyleValue, true); } } } } catch (Exception ex) { Debug.Fail(ex.ToString()); } } /// /// /// Notification that is fired upon the designer being attached to the behavior. /// [Obsolete("The recommended alternative is ControlDesigner.Tag. http://go.microsoft.com/fwlink/?linkid=14202")] protected override void OnBehaviorAttached() { base.OnBehaviorAttached(); if (!IsWebControl) { return; } WebControl control = (WebControl)Component; string colorValue; colorValue = System.Drawing.ColorTranslator.ToHtml((System.Drawing.Color)control.BackColor); if (colorValue.Length > 0) { MapPropertyToStyle("BackColor", colorValue); } colorValue = System.Drawing.ColorTranslator.ToHtml((System.Drawing.Color)control.ForeColor); if (colorValue.Length > 0) { MapPropertyToStyle("ForeColor", colorValue); } colorValue = System.Drawing.ColorTranslator.ToHtml((System.Drawing.Color)control.BorderColor); if (colorValue.Length > 0) { MapPropertyToStyle("BorderColor", colorValue); } BorderStyle borderStyle = control.BorderStyle; if (borderStyle != BorderStyle.NotSet) { MapPropertyToStyle("BorderStyle", borderStyle); } Unit borderWidth = control.BorderWidth; if (borderWidth.IsEmpty == false && borderWidth.Value != 0) { MapPropertyToStyle("BorderWidth", borderWidth.ToString(CultureInfo.InvariantCulture)); } Unit width = control.Width; if (!width.IsEmpty && width.Value != 0) { MapPropertyToStyle("Width", width.ToString(CultureInfo.InvariantCulture)); } Unit height = control.Height; if (!height.IsEmpty && height.Value != 0) { MapPropertyToStyle("Height", height.ToString(CultureInfo.InvariantCulture)); } string fontName = control.Font.Name; if (fontName.Length != 0) { MapPropertyToStyle("Font.Name", fontName); } FontUnit fontSize = control.Font.Size; if (fontSize != FontUnit.Empty) { MapPropertyToStyle("Font.Size", fontSize.ToString(CultureInfo.InvariantCulture)); } bool boolValue = control.Font.Bold; if (boolValue) { MapPropertyToStyle("Font.Bold", boolValue); } boolValue = control.Font.Italic; if (boolValue) { MapPropertyToStyle("Font.Italic", boolValue); } boolValue = control.Font.Underline; if (boolValue) { MapPropertyToStyle("Font.Underline", boolValue); } boolValue = control.Font.Strikeout; if (boolValue) { MapPropertyToStyle("Font.Strikeout", boolValue); } boolValue = control.Font.Overline; if (boolValue) { MapPropertyToStyle("Font.Overline", boolValue); } } ////// public override void UpdateDesignTimeHtml() { // do nothing } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UrlRoutingModule.cs
- WinCategoryAttribute.cs
- ImpersonationContext.cs
- DesignOnlyAttribute.cs
- XmlSerializableServices.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- ServiceSecurityContext.cs
- SQLConvert.cs
- ComponentRenameEvent.cs
- RadioButtonList.cs
- MailAddressParser.cs
- DelegateHelpers.cs
- CreateUserErrorEventArgs.cs
- AspNetHostingPermission.cs
- SamlAdvice.cs
- MLangCodePageEncoding.cs
- SoapEnvelopeProcessingElement.cs
- DataGridCaption.cs
- TextOnlyOutput.cs
- tibetanshape.cs
- CapabilitiesSection.cs
- PersianCalendar.cs
- ValidationResult.cs
- HighlightVisual.cs
- WebPartDisplayModeCancelEventArgs.cs
- SubstitutionList.cs
- XmlSchemaAnyAttribute.cs
- CodeRemoveEventStatement.cs
- MetadataException.cs
- Lasso.cs
- OrderedDictionaryStateHelper.cs
- XmlAttributeCollection.cs
- SoapSchemaMember.cs
- URLMembershipCondition.cs
- SQLDouble.cs
- DataListItemCollection.cs
- DataGridColumnFloatingHeader.cs
- RtType.cs
- CollectionMarkupSerializer.cs
- VectorConverter.cs
- FormViewCommandEventArgs.cs
- Triplet.cs
- BitmapEffectGroup.cs
- AspNetCompatibilityRequirementsAttribute.cs
- FrugalMap.cs
- EntityAdapter.cs
- DataControlFieldCollection.cs
- CellIdBoolean.cs
- EntitySqlQueryCacheEntry.cs
- DragDrop.cs
- UnsignedPublishLicense.cs
- panel.cs
- MarkupWriter.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- BamlBinaryWriter.cs
- DateTimePicker.cs
- ContextBase.cs
- QueryableDataSourceHelper.cs
- ProviderException.cs
- HMAC.cs
- ToolboxComponentsCreatingEventArgs.cs
- FileChangesMonitor.cs
- DataGridViewCheckBoxCell.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- IssuanceLicense.cs
- TreeView.cs
- ListViewGroupItemCollection.cs
- ComNativeDescriptor.cs
- Cursor.cs
- WindowsTooltip.cs
- EntityCommand.cs
- PrimitiveSchema.cs
- NotifyCollectionChangedEventArgs.cs
- FunctionDescription.cs
- Tool.cs
- AccessDataSourceView.cs
- TextRangeAdaptor.cs
- RayHitTestParameters.cs
- StringInfo.cs
- cryptoapiTransform.cs
- DoubleAnimationUsingPath.cs
- PropertyEmitterBase.cs
- BindToObject.cs
- GeometryCombineModeValidation.cs
- PageStatePersister.cs
- CompressStream.cs
- URLAttribute.cs
- ReferenceConverter.cs
- FontFamilyValueSerializer.cs
- MatrixAnimationUsingPath.cs
- ImportException.cs
- MimeMapping.cs
- UnsignedPublishLicense.cs
- CodeIdentifiers.cs
- EntitySet.cs
- AuthenticationModulesSection.cs
- JsonWriter.cs
- ActivitySurrogateSelector.cs
- RemotingAttributes.cs
- LicenseException.cs