Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Base / System / Windows / Size.cs / 1 / Size.cs
//------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2001, 2002 // // File: Size.cs //----------------------------------------------------------------------------- using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Text; using System.Collections; using System.Globalization; using System.Windows; using System.Windows.Media; using System.Runtime.InteropServices; namespace System.Windows { ////// Size - A value type which defined a size in terms of non-negative width and height /// public partial struct Size { #region Constructors ////// Constructor which sets the size's initial values. Width and Height must be non-negative /// /// double - The initial Width /// double - THe initial Height public Size(double width, double height) { if (width < 0 || height < 0) { throw new System.ArgumentException(SR.Get(SRID.Size_WidthAndHeightCannotBeNegative)); } _width = width; _height = height; } #endregion Constructors #region Statics ////// Empty - a static property which provides an Empty size. Width and Height are /// negative-infinity. This is the only situation /// where size can be negative. /// public static Size Empty { get { return s_empty; } } #endregion Statics #region Public Methods and Properties ////// IsEmpty - this returns true if this size is the Empty size. /// Note: If size is 0 this Size still contains a 0 or 1 dimensional set /// of points, so this method should not be used to check for 0 area. /// public bool IsEmpty { get { return _width < 0; } } ////// Width - Default is 0, must be non-negative /// public double Width { get { return _width; } set { if (IsEmpty) { throw new System.InvalidOperationException(SR.Get(SRID.Size_CannotModifyEmptySize)); } if (value < 0) { throw new System.ArgumentException(SR.Get(SRID.Size_WidthCannotBeNegative)); } _width = value; } } ////// Height - Default is 0, must be non-negative. /// public double Height { get { return _height; } set { if (IsEmpty) { throw new System.InvalidOperationException(SR.Get(SRID.Size_CannotModifyEmptySize)); } if (value < 0) { throw new System.ArgumentException(SR.Get(SRID.Size_HeightCannotBeNegative)); } _height = value; } } #endregion Public Methods #region Public Operators ////// Explicit conversion to Vector. /// ////// Vector - A Vector equal to this Size /// /// Size - the Size to convert to a Vector public static explicit operator Vector(Size size) { return new Vector(size._width, size._height); } ////// Explicit conversion to Point /// ////// Point - A Point equal to this Size /// /// Size - the Size to convert to a Point public static explicit operator Point(Size size) { return new Point(size._width, size._height); } #endregion Public Operators #region Private Methods static private Size CreateEmptySize() { Size size = new Size(); // We can't set these via the property setters because negatives widths // are rejected in those APIs. size._width = Double.NegativeInfinity; size._height = Double.NegativeInfinity; return size; } #endregion Private Methods #region Private Fields private readonly static Size s_empty = CreateEmptySize(); #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2001, 2002 // // File: Size.cs //----------------------------------------------------------------------------- using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Text; using System.Collections; using System.Globalization; using System.Windows; using System.Windows.Media; using System.Runtime.InteropServices; namespace System.Windows { ////// Size - A value type which defined a size in terms of non-negative width and height /// public partial struct Size { #region Constructors ////// Constructor which sets the size's initial values. Width and Height must be non-negative /// /// double - The initial Width /// double - THe initial Height public Size(double width, double height) { if (width < 0 || height < 0) { throw new System.ArgumentException(SR.Get(SRID.Size_WidthAndHeightCannotBeNegative)); } _width = width; _height = height; } #endregion Constructors #region Statics ////// Empty - a static property which provides an Empty size. Width and Height are /// negative-infinity. This is the only situation /// where size can be negative. /// public static Size Empty { get { return s_empty; } } #endregion Statics #region Public Methods and Properties ////// IsEmpty - this returns true if this size is the Empty size. /// Note: If size is 0 this Size still contains a 0 or 1 dimensional set /// of points, so this method should not be used to check for 0 area. /// public bool IsEmpty { get { return _width < 0; } } ////// Width - Default is 0, must be non-negative /// public double Width { get { return _width; } set { if (IsEmpty) { throw new System.InvalidOperationException(SR.Get(SRID.Size_CannotModifyEmptySize)); } if (value < 0) { throw new System.ArgumentException(SR.Get(SRID.Size_WidthCannotBeNegative)); } _width = value; } } ////// Height - Default is 0, must be non-negative. /// public double Height { get { return _height; } set { if (IsEmpty) { throw new System.InvalidOperationException(SR.Get(SRID.Size_CannotModifyEmptySize)); } if (value < 0) { throw new System.ArgumentException(SR.Get(SRID.Size_HeightCannotBeNegative)); } _height = value; } } #endregion Public Methods #region Public Operators ////// Explicit conversion to Vector. /// ////// Vector - A Vector equal to this Size /// /// Size - the Size to convert to a Vector public static explicit operator Vector(Size size) { return new Vector(size._width, size._height); } ////// Explicit conversion to Point /// ////// Point - A Point equal to this Size /// /// Size - the Size to convert to a Point public static explicit operator Point(Size size) { return new Point(size._width, size._height); } #endregion Public Operators #region Private Methods static private Size CreateEmptySize() { Size size = new Size(); // We can't set these via the property setters because negatives widths // are rejected in those APIs. size._width = Double.NegativeInfinity; size._height = Double.NegativeInfinity; return size; } #endregion Private Methods #region Private Fields private readonly static Size s_empty = CreateEmptySize(); #endregion Private Fields } } // 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
- CustomSignedXml.cs
- EntityContainerRelationshipSet.cs
- ToolStripDropDown.cs
- RemotingServices.cs
- TemplateBamlRecordReader.cs
- WebPartTransformerAttribute.cs
- SmiEventSink.cs
- DesignerSerializationVisibilityAttribute.cs
- HideDisabledControlAdapter.cs
- PaperSize.cs
- RowsCopiedEventArgs.cs
- CqlWriter.cs
- PolicyStatement.cs
- Int32RectConverter.cs
- SynchronizedChannelCollection.cs
- X509CertificateValidator.cs
- CircleHotSpot.cs
- TimeoutValidationAttribute.cs
- ApplicationId.cs
- BorderGapMaskConverter.cs
- DataSourceProvider.cs
- KeyEventArgs.cs
- TransactedBatchingBehavior.cs
- WorkflowDesignerColors.cs
- LinkButton.cs
- DetailsViewRow.cs
- CollectionViewProxy.cs
- SqlRowUpdatedEvent.cs
- ReadWriteObjectLock.cs
- PermissionRequestEvidence.cs
- SerializationHelper.cs
- CompressStream.cs
- PathSegmentCollection.cs
- SemanticResultKey.cs
- StrokeSerializer.cs
- ProviderConnectionPoint.cs
- SuppressMessageAttribute.cs
- DataColumnPropertyDescriptor.cs
- DataMemberFieldConverter.cs
- EntityModelSchemaGenerator.cs
- DataGridTable.cs
- WebConfigurationHost.cs
- DescendentsWalkerBase.cs
- entityreference_tresulttype.cs
- TranslateTransform.cs
- EtwTrace.cs
- RotateTransform3D.cs
- MetadataException.cs
- XmlSchemaExporter.cs
- DataGridAutoFormatDialog.cs
- PropertyMapper.cs
- CodeExpressionStatement.cs
- AuthenticationModuleElementCollection.cs
- TabItemWrapperAutomationPeer.cs
- XmlDocumentSurrogate.cs
- DescendantBaseQuery.cs
- CompiledIdentityConstraint.cs
- SqlClientWrapperSmiStreamChars.cs
- IssuanceTokenProviderState.cs
- CoTaskMemHandle.cs
- KeyValuePairs.cs
- QuestionEventArgs.cs
- DataGridViewRowConverter.cs
- UnsafeNativeMethods.cs
- TextFormatterHost.cs
- TreeViewDataItemAutomationPeer.cs
- LocalizationComments.cs
- ToolStripPanelRenderEventArgs.cs
- GcHandle.cs
- ReceiveErrorHandling.cs
- FixedStringLookup.cs
- TaskFormBase.cs
- Slider.cs
- DotExpr.cs
- Listbox.cs
- WebControlToolBoxItem.cs
- DefaultTextStore.cs
- SvcMapFileSerializer.cs
- XPathDocument.cs
- TextTreeExtractElementUndoUnit.cs
- EntityCommandCompilationException.cs
- DbConnectionPoolGroup.cs
- ReadOnlyDataSource.cs
- InstancePersistenceEvent.cs
- AsmxEndpointPickerExtension.cs
- TraceFilter.cs
- TypeExtensionSerializer.cs
- AttributeCollection.cs
- ComponentEvent.cs
- SQLGuidStorage.cs
- ListViewTableCell.cs
- InputScope.cs
- SignatureToken.cs
- XamlReaderConstants.cs
- TriggerBase.cs
- ObjectDataSourceSelectingEventArgs.cs
- CodeSubDirectoriesCollection.cs
- DateTimeSerializationSection.cs
- MenuRenderer.cs
- HtmlHead.cs