2 // System.Drawing.SizeF.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // Copyright (C) 2001 Mike Kestner
8 // Copyright (C) 2004 Novell, Inc. http://www.novell.com
12 using System.Runtime.InteropServices;
13 using System.ComponentModel;
15 namespace System.Drawing
21 // Private height and width fields.
24 // -----------------------
25 // Public Shared Members
26 // -----------------------
29 /// Empty Shared Field
33 /// An uninitialized SizeF Structure.
36 public static readonly SizeF Empty;
43 /// Addition of two SizeF structures.
46 public static SizeF operator + (SizeF sz1, SizeF sz2)
48 return new SizeF (sz1.Width + sz2.Width,
49 sz1.Height + sz2.Height);
57 /// Compares two SizeF objects. The return value is
58 /// based on the equivalence of the Width and Height
59 /// properties of the two Sizes.
62 public static bool operator == (SizeF sz_a, SizeF sz_b)
64 return ((sz_a.Width == sz_b.Width) &&
65 (sz_a.Height == sz_b.Height));
69 /// Inequality Operator
73 /// Compares two SizeF objects. The return value is
74 /// based on the equivalence of the Width and Height
75 /// properties of the two Sizes.
78 public static bool operator != (SizeF sz_a, SizeF sz_b)
80 return ((sz_a.Width != sz_b.Width) ||
81 (sz_a.Height != sz_b.Height));
85 /// Subtraction Operator
89 /// Subtracts two SizeF structures.
92 public static SizeF operator - (SizeF sz1, SizeF sz2)
94 return new SizeF (sz1.Width - sz2.Width,
95 sz1.Height - sz2.Height);
99 /// SizeF to PointF Conversion
103 /// Returns a PointF based on the dimensions of a given
104 /// SizeF. Requires explicit cast.
107 public static explicit operator PointF (SizeF sz)
109 return new PointF (sz.Width, sz.Height);
113 // -----------------------
114 // Public Constructors
115 // -----------------------
118 /// SizeF Constructor
122 /// Creates a SizeF from a PointF value.
125 public SizeF (PointF pt)
132 /// SizeF Constructor
136 /// Creates a SizeF from an existing SizeF value.
139 public SizeF (SizeF sz)
146 /// SizeF Constructor
150 /// Creates a SizeF from specified dimensions.
153 public SizeF (float width, float height)
159 // -----------------------
160 // Public Instance Members
161 // -----------------------
168 /// Indicates if both Width and Height are zero.
172 public bool IsEmpty {
174 return ((wd == 0.0) && (ht == 0.0));
183 /// The Width coordinate of the SizeF.
200 /// The Height coordinate of the SizeF.
203 public float Height {
217 /// Checks equivalence of this SizeF and another object.
220 public override bool Equals (object o)
225 return (this == (SizeF) o);
229 /// GetHashCode Method
233 /// Calculates a hashing value.
236 public override int GetHashCode ()
238 return (int) wd ^ (int) ht;
241 public PointF ToPointF ()
243 return new PointF (wd, ht);
246 public Size ToSize ()
254 return new Size (w, h);
262 /// Formats the SizeF as a string in coordinate notation.
265 public override string ToString ()
267 return String.Format ("{{Width={0}, Height={1}}}", wd, ht);