123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- using System.Drawing;
- using System.Windows.Forms;
- namespace Microsoft.Drawing
- {
-
-
-
- public static class RectangleEx
- {
-
-
-
-
- public static void MakeNotEmpty(ref Rectangle rect)
- {
- if (rect.Width < 1)
- rect.Width = 1;
- if (rect.Height < 1)
- rect.Height = 1;
- }
-
-
-
-
-
- public static bool IsVisible(Rectangle rect)
- {
- return rect.Width > 0 && rect.Height > 0;
- }
-
-
-
-
-
-
-
- public static Rectangle Inflate(Rectangle rect, TabAlignment align, int value)
- {
- switch (align)
- {
- case TabAlignment.Top:
- rect.Y -= value;
- rect.Height += value;
- break;
- case TabAlignment.Bottom:
- rect.Height += value;
- break;
- case TabAlignment.Left:
- rect.X -= value;
- rect.Width += value;
- break;
- case TabAlignment.Right:
- rect.Width += value;
- break;
- default:
- break;
- }
- return rect;
- }
-
-
-
-
-
-
-
-
- public static Rectangle Inflate(Rectangle rect, TabAlignment align, int value, int revalue)
- {
- switch (align)
- {
- case TabAlignment.Top:
- rect.Y -= value;
- rect.Height += value + revalue;
- break;
- case TabAlignment.Bottom:
- rect.Y -= revalue;
- rect.Height += revalue + value;
- break;
- case TabAlignment.Left:
- rect.X -= value;
- rect.Width += value + revalue;
- break;
- case TabAlignment.Right:
- rect.X -= revalue;
- rect.Width += revalue + value;
- break;
- default:
- break;
- }
- return rect;
- }
-
-
-
-
-
-
-
- public static Rectangle InflateSide(Rectangle rect, TabAlignment align, int value)
- {
- int half = value / 2;
- switch (align)
- {
- case TabAlignment.Top:
- case TabAlignment.Bottom:
- rect.X -= half;
- rect.Width += value;
- break;
- case TabAlignment.Left:
- case TabAlignment.Right:
- rect.Y -= half;
- rect.Height += value;
- break;
- default:
- break;
- }
- return rect;
- }
-
-
-
-
-
-
-
- public static Rectangle Adjust(Rectangle rect, TabAlignment align, int value)
- {
- switch (align)
- {
- case TabAlignment.Top:
- rect.Y += (rect.Height - value);
- rect.Height = value;
- break;
- case TabAlignment.Bottom:
- rect.Height = value;
- break;
- case TabAlignment.Left:
- rect.X += (rect.Width - value);
- rect.Width = value;
- break;
- case TabAlignment.Right:
- rect.Width = value;
- break;
- default:
- break;
- }
- return rect;
- }
-
-
-
-
-
-
-
-
- public static Rectangle Align(Rectangle rect, Rectangle rectStand, TabAlignment align, int offset)
- {
- int value;
- switch (align)
- {
- case TabAlignment.Top:
- value = rect.Y - rectStand.Y + offset;
- rect.Y -= value;
- rect.Height += value;
- break;
- case TabAlignment.Bottom:
- value = rectStand.Bottom - rect.Bottom + offset;
- rect.Height += value;
- break;
- case TabAlignment.Left:
- value = rect.X - rectStand.X + offset;
- rect.X -= value;
- rect.Width += value;
- break;
- case TabAlignment.Right:
- value = rectStand.Right - rect.Right + offset;
- rect.Width += value;
- break;
- default:
- break;
- }
- return rect;
- }
-
-
-
-
-
-
- public static Rectangle Add(Rectangle rect, Padding padding)
- {
- return new Rectangle(rect.Left - padding.Left, rect.Top - padding.Top, rect.Width + padding.Horizontal, rect.Height + padding.Vertical);
- }
-
-
-
-
-
-
- public static Rectangle Subtract(Rectangle rect, Padding padding)
- {
- return new Rectangle(rect.Left + padding.Left, rect.Top + padding.Top, rect.Width - padding.Horizontal, rect.Height - padding.Vertical);
- }
-
-
-
-
-
-
- public static Rectangle Offset(Rectangle rect, Point pos)
- {
- rect.Offset(pos);
- return rect;
- }
-
-
-
-
-
-
-
- public static Rectangle Offset(Rectangle rect, int x, int y)
- {
- rect.Offset(x, y);
- return rect;
- }
- }
- }
|