Transparent form without affecting buttons

the_atom

Active member
Joined
Apr 18, 2007
Messages
26
Programming Experience
Beginner
Is it possible that i will make the opacity of my form 0 and not affecting the buttons, labels inside of it?
 
Sure, you can set a region to be the whole form, then subtract the regions of each button from it..

Here is the code I made as an example. It's in C# but the comments should help:

VB.NET:
      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;

Here is what it looks like (greyscaled to reduce size, sensitive elements blurred):
 

Attachments

  • Image1.png
    Image1.png
    72 KB · Views: 30
Back
Top