InitializeComponent();
//when we clip a button, it looks weird if we dont shift the clip region
//down and right by 3 pixles. this gives me a nice border to my buttons
//but you can play with these values and also the size if you want to clip
//your buttons some more
Point p = new Point(3, 3);
Point loc;
//create a new region of no size
Region r = new Region(new Rectangle(0, 0, 0, 0));
//iterate all the controls looking for buttons (the only thing in the UI)
foreach(Control ctrl in this.Controls) {
if(ctrl is Button) {
//take the buttons top left corner
loc = ctrl.Location;
//offset the location(doesnt move the button, just the "stencil" start point
loc.Offset(p);
//add a rectangle tha size of the button, to the region
r.Union(new Rectangle(loc, ctrl.Size));
}
}
//apply the clip
this.Region = r;