System.Drawing.Rectangle.Equals C# (CSharp) Method

Equals() public method

Tests whether obj is a with the same location and size of this Rectangle.

public Equals ( object obj ) : bool
obj object
return bool
        public override bool Equals(object obj)
        {
            if (!(obj is Rectangle))
                return false;

            Rectangle comp = (Rectangle)obj;

            return (comp.X == X) && (comp.Y == Y) && (comp.Width == Width) && (comp.Height == Height);
        }

Usage Example

		public void Update(Graphics g, string text, Font font, Padding internalBounds,
			Rectangle bounds, Color color, TextFormatFlags formatFlags, IThemeTextOption[] options) {

			IntPtr compatHdc = this._TextHDC;

			if (bounds.Equals(_TextHDCBounds)) {
				//Same bounds, reuse HDC and Clear it
				IntPtr hClearBrush = Native.GDI.CreateSolidBrush(ColorTranslator.ToWin32(Color.Black));
				Native.RECT cleanRect = new Native.RECT(bounds);
				Native.GDI.FillRect(compatHdc, ref cleanRect, hClearBrush);
				Native.GDI.DeleteObject(hClearBrush);
			}
			else {
				//Other bounds, create new HDC
				IntPtr outputHdc = g.GetHdc();
				IntPtr DIB;
				compatHdc = CreateNewHDC(outputHdc, bounds, out DIB);

				//Store new data
				_TextHDC = compatHdc;
				_TextHDCBounds = bounds;

				//Clear up
				CleanUpHDC(DIB);
				g.ReleaseHdc(outputHdc);
			}

			DrawOnHDC(compatHdc, text, font, internalBounds, bounds, color, formatFlags, options);
		}
All Usage Examples Of System.Drawing.Rectangle::Equals