2 // System.Drawing.SizeF.cs
5 // Mike Kestner (mkestner@speakeasy.net)
7 // (C) 2001 Mike Kestner
11 using System.Runtime.InteropServices;
12 using System.ComponentModel;
14 namespace System.Drawing {
20 // Private height and width fields.
23 // -----------------------
24 // Public Shared Members
25 // -----------------------
28 /// Empty Shared Field
32 /// An uninitialized SizeF Structure.
35 public static readonly SizeF Empty;
42 /// Addition of two SizeF structures.
45 public static SizeF operator + (SizeF sz1, SizeF sz2)
47 return new SizeF (sz1.Width + sz2.Width,
48 sz1.Height + sz2.Height);
56 /// Compares two SizeF objects. The return value is
57 /// based on the equivalence of the Width and Height
58 /// properties of the two Sizes.
61 public static bool operator == (SizeF sz_a, SizeF sz_b)
63 return ((sz_a.Width == sz_b.Width) &&
64 (sz_a.Height == sz_b.Height));
68 /// Inequality Operator
72 /// Compares two SizeF objects. The return value is
73 /// based on the equivalence of the Width and Height
74 /// properties of the two Sizes.
77 public static bool operator != (SizeF sz_a, SizeF sz_b)
79 return ((sz_a.Width != sz_b.Width) ||
80 (sz_a.Height != sz_b.Height));
84 /// Subtraction Operator
88 /// Subtracts two SizeF structures.
91 public static SizeF operator - (SizeF sz1, SizeF sz2)
93 return new SizeF (sz1.Width - sz2.Width,
94 sz1.Height - sz2.Height);
98 /// SizeF to PointF Conversion
102 /// Returns a PointF based on the dimensions of a given
103 /// SizeF. Requires explicit cast.
106 public static explicit operator PointF (SizeF sz)
108 return new PointF (sz.Width, sz.Height);
112 // -----------------------
113 // Public Constructors
114 // -----------------------
117 /// SizeF Constructor
121 /// Creates a SizeF from a PointF value.
124 public SizeF (PointF pt)
131 /// SizeF Constructor
135 /// Creates a SizeF from an existing SizeF value.
138 public SizeF (SizeF sz)
145 /// SizeF Constructor
149 /// Creates a SizeF from specified dimensions.
152 public SizeF (float width, float height)
158 // -----------------------
159 // Public Instance Members
160 // -----------------------
167 /// Indicates if both Width and Height are zero.
171 public bool IsEmpty {
173 return ((wd == 0.0) && (ht == 0.0));
182 /// The Width coordinate of the SizeF.
199 /// The Height coordinate of the SizeF.
202 public float Height {
216 /// Checks equivalence of this SizeF and another object.
219 public override bool Equals (object o)
224 return (this == (SizeF) o);
228 /// GetHashCode Method
232 /// Calculates a hashing value.
235 public override int GetHashCode ()
237 return (int) wd ^ (int) ht;
240 public PointF ToPointF ()
242 return new PointF (wd, ht);
245 public Size ToSize ()
253 return new Size (w, h);
261 /// Formats the SizeF as a string in coordinate notation.
264 public override string ToString ()
266 return String.Format ("{{Width={0}, Height={1}}}", wd, ht);