Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- WebContext.cs
- WebPartConnectVerb.cs
- InvalidDocumentContentsException.cs
- FixedSOMPage.cs
- OfTypeExpression.cs
- PersistChildrenAttribute.cs
- Comparer.cs
- MessageBox.cs
- ByteViewer.cs
- RunClient.cs
- Int32AnimationUsingKeyFrames.cs
- ListViewEditEventArgs.cs
- ObjectTypeMapping.cs
- RemoteAsymmetricSignatureFormatter.cs
- DeviceContext2.cs
- ImageAttributes.cs
- PropertyInformation.cs
- SecurityTokenRequirement.cs
- EventDescriptor.cs
- CultureNotFoundException.cs
- ConvertersCollection.cs
- SecurityDescriptor.cs
- GroupBoxAutomationPeer.cs
- Guid.cs
- CounterSample.cs
- DataGridColumnEventArgs.cs
- WebSysDescriptionAttribute.cs
- ServicePoint.cs
- KeyFrames.cs
- TaskSchedulerException.cs
- cookieexception.cs
- DetailsViewDeleteEventArgs.cs
- BinHexDecoder.cs
- RijndaelManaged.cs
- BooleanAnimationBase.cs
- SpoolingTaskBase.cs
- securitycriticaldata.cs
- ToolStripButton.cs
- BindingExpressionUncommonField.cs
- DataConnectionHelper.cs
- handlecollector.cs
- ScopedKnownTypes.cs
- RichTextBox.cs
- SqlParameterCollection.cs
- Mappings.cs
- _FtpDataStream.cs
- XamlStackWriter.cs
- RemotingServices.cs
- TextDecoration.cs
- RenderData.cs
- OleDbParameter.cs
- EditorOptionAttribute.cs
- DynamicUpdateCommand.cs
- ConfigurationProperty.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- XsltCompileContext.cs
- MenuItemBinding.cs
- DataGridRelationshipRow.cs
- RichTextBoxConstants.cs
- XPathSelectionIterator.cs
- SimpleHandlerFactory.cs
- XslCompiledTransform.cs
- DbConnectionStringBuilder.cs
- DispatcherOperation.cs
- TypeDescriptor.cs
- Baml2006KnownTypes.cs
- FileReader.cs
- Crypto.cs
- BitmapPalette.cs
- Encoder.cs
- ListViewInsertEventArgs.cs
- RestHandler.cs
- HttpModuleAction.cs
- SerialStream.cs
- SystemResources.cs
- DocumentSchemaValidator.cs
- TextServicesLoader.cs
- EntitySet.cs
- documentsequencetextpointer.cs
- ProcessStartInfo.cs
- SiteMapProvider.cs
- OutOfMemoryException.cs
- DataSetUtil.cs
- RootBuilder.cs
- NameTable.cs
- CurrentChangingEventArgs.cs
- CacheRequest.cs
- GridItemProviderWrapper.cs
- CompilerGlobalScopeAttribute.cs
- RuntimeCompatibilityAttribute.cs
- FunctionQuery.cs
- NestedContainer.cs
- OleDbErrorCollection.cs
- CheckedPointers.cs
- PhysicalAddress.cs
- DeferredTextReference.cs
- EventProviderBase.cs
- isolationinterop.cs
- FrameworkPropertyMetadata.cs
- DeflateStream.cs