using System.Drawing;
using System.Runtime.InteropServices;
namespace Microsoft.Win32
{
///
/// 矩形结构定义
///
public static partial class NativeMethods
{
///
/// 矩形结构
///
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
///
/// 左上角水平坐标
///
public int left;
///
/// 左上角垂直坐标
///
public int top;
///
/// 右下角水平坐标
///
public int right;
///
/// 右下角垂直坐标
///
public int bottom;
///
/// 构造函数
///
/// 左上角水平坐标
/// 左上角垂直坐标
/// 右下角水平坐标
/// 右下角垂直坐标
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
///
/// 构造函数
///
/// Rectangle结构
public RECT(Rectangle r)
{
this.left = r.Left;
this.top = r.Top;
this.right = r.Right;
this.bottom = r.Bottom;
}
///
/// 构造函数
///
/// 左上角水平坐标
/// 左上角垂直坐标
/// 宽度
/// 高度
/// 矩形结构
public static NativeMethods.RECT FromXYWH(int x, int y, int width, int height)
{
return new NativeMethods.RECT(x, y, x + width, y + height);
}
///
/// 宽度
///
public int Width
{
get
{
return this.right - this.left;
}
}
///
/// 高度
///
public int Height
{
get
{
return this.bottom - this.top;
}
}
///
/// 左上角
///
public Point Location
{
get
{
return new Point(this.left, this.top);
}
}
///
/// 右下角
///
public Point BottomRight
{
get
{
return new Point(this.right, this.bottom);
}
}
///
/// 大小
///
public Size Size
{
get
{
return new Size(this.right - this.left, this.bottom - this.top);
}
}
///
/// 转换为 System.Drawing.Rectangle.
///
/// System.Drawing.Rectangle
public Rectangle ToRectangle()
{
return new Rectangle(this.left, this.top, this.right - this.left, this.bottom - this.top);
}
///
/// 是否包含指定点
///
/// 点
/// 包含返回true,否则返回false
public bool Contains(NativeMethods.POINT pt)
{
return this.Contains(pt.x, pt.y);
}
///
/// 是否包含指定点
///
/// 点
/// 包含返回true,否则返回false
public bool Contains(Point pt)
{
return this.Contains(pt.X, pt.Y);
}
///
/// 是否包含指定坐标
///
/// 水平坐标
/// 垂直坐标
/// 包含返回true,否则返回false
public bool Contains(int x, int y)
{
return ((this.left <= x) && (x < this.right) && (this.top <= y) && (y < this.bottom));
}
}
}
}