Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / Thickness.cs / 1 / Thickness.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // // File: Thickness.cs // // Description: Contains the Thickness (double x4) value type. // // History: // 06/02/2003 : greglett - created. // //--------------------------------------------------------------------------- using MS.Internal; using System.ComponentModel; using System.Globalization; namespace System.Windows { ////// Thickness is a value type used to describe the thickness of frame around a rectangle. /// It contains four doubles each corresponding to a side: Left, Top, Right, Bottom. /// [TypeConverter(typeof(ThicknessConverter))] [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] public struct Thickness : IEquatable{ //------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------- #region Constructors /// /// This constructur builds a Thickness with a specified value on every side. /// /// The specified uniform length. public Thickness(double uniformLength) { _Left = _Top = _Right = _Bottom = uniformLength; } ////// This constructor builds a Thickness with the specified number of pixels on each side. /// /// The thickness for the left side. /// The thickness for the top side. /// The thickness for the right side. /// The thickness for the bottom side. public Thickness(double left, double top, double right, double bottom) { _Left = left; _Top = top; _Right = right; _Bottom = bottom; } #endregion //-------------------------------------------------------------------- // // Public Methods // //------------------------------------------------------------------- #region Public Methods ////// This function compares to the provided object for type and value equality. /// /// Object to compare ///True if object is a Thickness and all sides of it are equal to this Thickness'. public override bool Equals(object obj) { if (obj is Thickness) { Thickness otherObj = (Thickness)obj; return (this == otherObj); } return (false); } ////// Compares this instance of Thickness with another instance. /// /// Thickness instance to compare. ///public bool Equals(Thickness thickness) { return (this == thickness); } /// true if this Thickness instance has the same value /// and unit type as thickness./// This function returns a hash code. /// ///Hash code public override int GetHashCode() { return _Left.GetHashCode() ^ _Top.GetHashCode() ^ _Right.GetHashCode() ^ _Bottom.GetHashCode(); } ////// Converts this Thickness object to a string. /// ///String conversion. public override string ToString() { return ThicknessConverter.ToString(this, CultureInfo.InvariantCulture); } ////// Converts this Thickness object to a string. /// ///String conversion. internal string ToString(CultureInfo cultureInfo) { return ThicknessConverter.ToString(this, cultureInfo); } internal bool IsZero { get { return DoubleUtil.IsZero(Left) && DoubleUtil.IsZero(Top) && DoubleUtil.IsZero(Right) && DoubleUtil.IsZero(Bottom); } } internal bool IsUniform { get { return DoubleUtil.AreClose(Left, Top) && DoubleUtil.AreClose(Left, Right) && DoubleUtil.AreClose(Left, Bottom); } } ////// Verifies if this Thickness contains only valid values /// The set of validity checks is passed as parameters. /// /// allows negative values /// allows Double.NaN /// allows Double.PositiveInfinity /// allows Double.NegativeInfinity ///Whether or not the thickness complies to the range specified internal bool IsValid(bool allowNegative, bool allowNaN, bool allowPositiveInfinity, bool allowNegativeInfinity) { if(!allowNegative) { if(Left < 0d || Right < 0d || Top < 0d || Bottom < 0d) return false; } if(!allowNaN) { if(DoubleUtil.IsNaN(Left) || DoubleUtil.IsNaN(Right) || DoubleUtil.IsNaN(Top) || DoubleUtil.IsNaN(Bottom)) return false; } if(!allowPositiveInfinity) { if(Double.IsPositiveInfinity(Left) || Double.IsPositiveInfinity(Right) || Double.IsPositiveInfinity(Top) || Double.IsPositiveInfinity(Bottom)) { return false; } } if(!allowNegativeInfinity) { if(Double.IsNegativeInfinity(Left) || Double.IsNegativeInfinity(Right) || Double.IsNegativeInfinity(Top) || Double.IsNegativeInfinity(Bottom)) { return false; } } return true; } ////// Compares two thicknesses for fuzzy equality. This function /// helps compensate for the fact that double values can /// acquire error when operated upon /// /// The thickness to compare to this ///Whether or not the two points are equal internal bool IsClose(Thickness thickness) { return ( DoubleUtil.AreClose(Left, thickness.Left) && DoubleUtil.AreClose(Top, thickness.Top) && DoubleUtil.AreClose(Right, thickness.Right) && DoubleUtil.AreClose(Bottom, thickness.Bottom)); } ////// Compares two thicknesses for fuzzy equality. This function /// helps compensate for the fact that double values can /// acquire error when operated upon /// /// The first thickness to compare /// The second thickness to compare ///Whether or not the two thicknesses are equal static internal bool AreClose(Thickness thickness0, Thickness thickness1) { return thickness0.IsClose(thickness1); } #endregion //-------------------------------------------------------------------- // // Public Operators // //-------------------------------------------------------------------- #region Public Operators ////// Overloaded operator to compare two Thicknesses for equality. /// /// first Thickness to compare /// second Thickness to compare ///True if all sides of the Thickness are equal, false otherwise // SEEALSO public static bool operator==(Thickness t1, Thickness t2) { return ( (t1._Left == t2._Left || (DoubleUtil.IsNaN(t1._Left) && DoubleUtil.IsNaN(t2._Left))) && (t1._Top == t2._Top || (DoubleUtil.IsNaN(t1._Top) && DoubleUtil.IsNaN(t2._Top))) && (t1._Right == t2._Right || (DoubleUtil.IsNaN(t1._Right) && DoubleUtil.IsNaN(t2._Right))) && (t1._Bottom == t2._Bottom || (DoubleUtil.IsNaN(t1._Bottom) && DoubleUtil.IsNaN(t2._Bottom))) ); } ////// Overloaded operator to compare two Thicknesses for inequality. /// /// first Thickness to compare /// second Thickness to compare ///False if all sides of the Thickness are equal, true otherwise // SEEALSO public static bool operator!=(Thickness t1, Thickness t2) { return (!(t1 == t2)); } #endregion //------------------------------------------------------------------- // // Public Properties // //-------------------------------------------------------------------- #region Public Properties ///This property is the Length on the thickness' left side public double Left { get { return _Left; } set { _Left = value; } } ///This property is the Length on the thickness' top side public double Top { get { return _Top; } set { _Top = value; } } ///This property is the Length on the thickness' right side public double Right { get { return _Right; } set { _Right = value; } } ///This property is the Length on the thickness' bottom side public double Bottom { get { return _Bottom; } set { _Bottom = value; } } #endregion //------------------------------------------------------------------- // // INternal API // //------------------------------------------------------------------- #region Internal API internal Size Size { get { return new Size(_Left + _Right, _Top + _Bottom); } } #endregion //------------------------------------------------------------------- // // Private Fields // //-------------------------------------------------------------------- #region Private Fields private double _Left; private double _Top; private double _Right; private double _Bottom; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // // File: Thickness.cs // // Description: Contains the Thickness (double x4) value type. // // History: // 06/02/2003 : greglett - created. // //--------------------------------------------------------------------------- using MS.Internal; using System.ComponentModel; using System.Globalization; namespace System.Windows { ////// Thickness is a value type used to describe the thickness of frame around a rectangle. /// It contains four doubles each corresponding to a side: Left, Top, Right, Bottom. /// [TypeConverter(typeof(ThicknessConverter))] [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] public struct Thickness : IEquatable{ //------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------- #region Constructors /// /// This constructur builds a Thickness with a specified value on every side. /// /// The specified uniform length. public Thickness(double uniformLength) { _Left = _Top = _Right = _Bottom = uniformLength; } ////// This constructor builds a Thickness with the specified number of pixels on each side. /// /// The thickness for the left side. /// The thickness for the top side. /// The thickness for the right side. /// The thickness for the bottom side. public Thickness(double left, double top, double right, double bottom) { _Left = left; _Top = top; _Right = right; _Bottom = bottom; } #endregion //-------------------------------------------------------------------- // // Public Methods // //------------------------------------------------------------------- #region Public Methods ////// This function compares to the provided object for type and value equality. /// /// Object to compare ///True if object is a Thickness and all sides of it are equal to this Thickness'. public override bool Equals(object obj) { if (obj is Thickness) { Thickness otherObj = (Thickness)obj; return (this == otherObj); } return (false); } ////// Compares this instance of Thickness with another instance. /// /// Thickness instance to compare. ///public bool Equals(Thickness thickness) { return (this == thickness); } /// true if this Thickness instance has the same value /// and unit type as thickness./// This function returns a hash code. /// ///Hash code public override int GetHashCode() { return _Left.GetHashCode() ^ _Top.GetHashCode() ^ _Right.GetHashCode() ^ _Bottom.GetHashCode(); } ////// Converts this Thickness object to a string. /// ///String conversion. public override string ToString() { return ThicknessConverter.ToString(this, CultureInfo.InvariantCulture); } ////// Converts this Thickness object to a string. /// ///String conversion. internal string ToString(CultureInfo cultureInfo) { return ThicknessConverter.ToString(this, cultureInfo); } internal bool IsZero { get { return DoubleUtil.IsZero(Left) && DoubleUtil.IsZero(Top) && DoubleUtil.IsZero(Right) && DoubleUtil.IsZero(Bottom); } } internal bool IsUniform { get { return DoubleUtil.AreClose(Left, Top) && DoubleUtil.AreClose(Left, Right) && DoubleUtil.AreClose(Left, Bottom); } } ////// Verifies if this Thickness contains only valid values /// The set of validity checks is passed as parameters. /// /// allows negative values /// allows Double.NaN /// allows Double.PositiveInfinity /// allows Double.NegativeInfinity ///Whether or not the thickness complies to the range specified internal bool IsValid(bool allowNegative, bool allowNaN, bool allowPositiveInfinity, bool allowNegativeInfinity) { if(!allowNegative) { if(Left < 0d || Right < 0d || Top < 0d || Bottom < 0d) return false; } if(!allowNaN) { if(DoubleUtil.IsNaN(Left) || DoubleUtil.IsNaN(Right) || DoubleUtil.IsNaN(Top) || DoubleUtil.IsNaN(Bottom)) return false; } if(!allowPositiveInfinity) { if(Double.IsPositiveInfinity(Left) || Double.IsPositiveInfinity(Right) || Double.IsPositiveInfinity(Top) || Double.IsPositiveInfinity(Bottom)) { return false; } } if(!allowNegativeInfinity) { if(Double.IsNegativeInfinity(Left) || Double.IsNegativeInfinity(Right) || Double.IsNegativeInfinity(Top) || Double.IsNegativeInfinity(Bottom)) { return false; } } return true; } ////// Compares two thicknesses for fuzzy equality. This function /// helps compensate for the fact that double values can /// acquire error when operated upon /// /// The thickness to compare to this ///Whether or not the two points are equal internal bool IsClose(Thickness thickness) { return ( DoubleUtil.AreClose(Left, thickness.Left) && DoubleUtil.AreClose(Top, thickness.Top) && DoubleUtil.AreClose(Right, thickness.Right) && DoubleUtil.AreClose(Bottom, thickness.Bottom)); } ////// Compares two thicknesses for fuzzy equality. This function /// helps compensate for the fact that double values can /// acquire error when operated upon /// /// The first thickness to compare /// The second thickness to compare ///Whether or not the two thicknesses are equal static internal bool AreClose(Thickness thickness0, Thickness thickness1) { return thickness0.IsClose(thickness1); } #endregion //-------------------------------------------------------------------- // // Public Operators // //-------------------------------------------------------------------- #region Public Operators ////// Overloaded operator to compare two Thicknesses for equality. /// /// first Thickness to compare /// second Thickness to compare ///True if all sides of the Thickness are equal, false otherwise // SEEALSO public static bool operator==(Thickness t1, Thickness t2) { return ( (t1._Left == t2._Left || (DoubleUtil.IsNaN(t1._Left) && DoubleUtil.IsNaN(t2._Left))) && (t1._Top == t2._Top || (DoubleUtil.IsNaN(t1._Top) && DoubleUtil.IsNaN(t2._Top))) && (t1._Right == t2._Right || (DoubleUtil.IsNaN(t1._Right) && DoubleUtil.IsNaN(t2._Right))) && (t1._Bottom == t2._Bottom || (DoubleUtil.IsNaN(t1._Bottom) && DoubleUtil.IsNaN(t2._Bottom))) ); } ////// Overloaded operator to compare two Thicknesses for inequality. /// /// first Thickness to compare /// second Thickness to compare ///False if all sides of the Thickness are equal, true otherwise // SEEALSO public static bool operator!=(Thickness t1, Thickness t2) { return (!(t1 == t2)); } #endregion //------------------------------------------------------------------- // // Public Properties // //-------------------------------------------------------------------- #region Public Properties ///This property is the Length on the thickness' left side public double Left { get { return _Left; } set { _Left = value; } } ///This property is the Length on the thickness' top side public double Top { get { return _Top; } set { _Top = value; } } ///This property is the Length on the thickness' right side public double Right { get { return _Right; } set { _Right = value; } } ///This property is the Length on the thickness' bottom side public double Bottom { get { return _Bottom; } set { _Bottom = value; } } #endregion //------------------------------------------------------------------- // // INternal API // //------------------------------------------------------------------- #region Internal API internal Size Size { get { return new Size(_Left + _Right, _Top + _Bottom); } } #endregion //------------------------------------------------------------------- // // Private Fields // //-------------------------------------------------------------------- #region Private Fields private double _Left; private double _Top; private double _Right; private double _Bottom; #endregion } } // 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
- ErrorHandler.cs
- WindowsAuthenticationModule.cs
- EventManager.cs
- HScrollBar.cs
- ServiceDescriptionReflector.cs
- StrokeCollection2.cs
- Blend.cs
- DbXmlEnabledProviderManifest.cs
- CommandField.cs
- RenderData.cs
- CodeArgumentReferenceExpression.cs
- TraversalRequest.cs
- BaseValidator.cs
- RepeatButtonAutomationPeer.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- QuaternionValueSerializer.cs
- TableCellCollection.cs
- SubstitutionList.cs
- WebBrowserPermission.cs
- WebPartVerbCollection.cs
- HeaderUtility.cs
- ChangePassword.cs
- PageThemeBuildProvider.cs
- PositiveTimeSpanValidator.cs
- RewritingSimplifier.cs
- ClientScriptManager.cs
- DesignOnlyAttribute.cs
- WebBrowserProgressChangedEventHandler.cs
- Column.cs
- CheckBoxStandardAdapter.cs
- ReturnValue.cs
- TraceRecords.cs
- TypeDescriptionProvider.cs
- FileDialog.cs
- CancellationTokenSource.cs
- PathSegment.cs
- Delegate.cs
- GregorianCalendar.cs
- TypedElement.cs
- GrammarBuilderWildcard.cs
- QueryNode.cs
- KoreanCalendar.cs
- NumberFormatInfo.cs
- DataSourceView.cs
- ConfigurationElementProperty.cs
- CodeDirectiveCollection.cs
- MbpInfo.cs
- StatusBarDrawItemEvent.cs
- TableLayoutSettings.cs
- IISUnsafeMethods.cs
- IPHostEntry.cs
- ItemCollection.cs
- SqlConnectionFactory.cs
- BackStopAuthenticationModule.cs
- ErrorFormatterPage.cs
- LongTypeConverter.cs
- StackSpiller.Generated.cs
- CodeStatement.cs
- HideDisabledControlAdapter.cs
- CodeNamespaceImportCollection.cs
- SubclassTypeValidator.cs
- Propagator.Evaluator.cs
- SqlWriter.cs
- DataSourceCache.cs
- BindingCollection.cs
- ThreadStartException.cs
- DirectoryInfo.cs
- XmlSchemaIdentityConstraint.cs
- FunctionQuery.cs
- BaseComponentEditor.cs
- HttpListenerException.cs
- WhereQueryOperator.cs
- PropertyChangedEventArgs.cs
- AuthorizationBehavior.cs
- DataBindingHandlerAttribute.cs
- ContextToken.cs
- TableParagraph.cs
- PeerNameResolver.cs
- PromptBuilder.cs
- XmlNotation.cs
- WeakReferenceList.cs
- DataRowExtensions.cs
- PresentationAppDomainManager.cs
- XmlName.cs
- GetLedgerEntryForRecipientRequest.cs
- IsolatedStorage.cs
- _ContextAwareResult.cs
- ControlCollection.cs
- VirtualizingPanel.cs
- FixedDSBuilder.cs
- MetafileHeaderWmf.cs
- XmlAnyElementAttributes.cs
- CopyAttributesAction.cs
- RouteValueExpressionBuilder.cs
- GridSplitter.cs
- PersonalizationProviderCollection.cs
- VisualStyleRenderer.cs
- OdbcStatementHandle.cs
- DescendantQuery.cs
- StartUpEventArgs.cs