using System.Drawing;
using System.Windows.Forms;
namespace PathStuff
{
public static class PathExtensions
{
public static void MakeHole(this Control cntrl, Rectangle xrect)
{
var region = new Region(cntrl.ClientRectangle);
region.Exclude(xrect);
cntrl.Region = region;
}
public static void MakeHoleCenteredProportional(this Control cntrl, int scaleX, int scaleY)
{
var rect = new Rectangle();
rect.Size = cntrl.ClientRectangle.Size;
Region region = new Region(rect);
rect.Inflate(cntrl.Width / (scaleX * -2), cntrl.Height / (scaleY * -2));
region.Exclude(rect);
cntrl.Region = region;
}
}
}
Sample uses in a Form:
using PathStuff;
namespace YourForm
{
private void Form1_Load(object sender, EventArgs e)
{
PathExtensions.MakeHole(this, new Rectangle(100,100, 100, 100));
PathExtensions.MakeHoleCenteredProportional(this Control cntrl, (this, 2, 2);
}
};
Note the 'MakeHoleCenteredProportional method makes a hole centered in the Control; its size is determined by the ratios supplied: a value of #2 will create length, or width, of half the size of the corresponding dimension of the Control.
Suggestion: use double-buffering with Forms, or UserControls with this.