This is a really cool idea - I will probably use it, so thanks. Anyway, my solution is really simple... open a new 50% opaque form over your current one and then custom draw a background image for that form with a rectangle matching the bounds of the control you want to highlight filled in the color of the transparency key.
In my rough sample, I called this form the 'LBform' and the meat of it is this:
public Rectangle ControlBounds { get; set; }
private void LBform_Load(object sender, EventArgs e)
{
Bitmap background = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(background);
g.FillRectangle(Brushes.Fuchsia, this.ControlBounds);
g.Flush();
this.BackgroundImage = background;
this.Invalidate();
}
Color.Fuchia is the TransparencyKey for this semi-opaque form, so you will be able to see through the rectangle drawn and interact with anything within it's bounds on the main form.
In the experimental project I whipped up to try this, I used a UserControl dynamically added to the form, but you could just as easily use a control already on the form. In the main form (the one you are obscuring) I put the relevant code into a button click:
private void button1_Click(object sender, EventArgs e)
{
// setup user control:
UserControl1 uc1 = new UserControl1();
uc1.Left = (this.Width - uc1.Width) / 2;
uc1.Top = (this.Height - uc1.Height) / 2;
this.Controls.Add(uc1);
uc1.BringToFront();
// load the lightbox form:
LBform lbform = new LBform();
lbform.SetBounds(this.Left + 8, this.Top + 30, this.ClientRectangle.Width, this.ClientRectangle.Height);
lbform.ControlBounds = uc1.Bounds;
lbform.Owner = this;
lbform.Show();
}
Really basic stuff that you can do your own way if you like, but it's just adding the usercontrol, then setting the lightbox form over the main form and setting the bounds property to render the full transparency in the right place. Things like form dragging and closing the lightbox form and UserControl aren't handled in my quick sample. Oh and don't forget to dispose the Graphics instance - I left that out too (it's late, I'm really tired).
Here's my very did-it-in-20-minutes demo