-1

I have scenario in which BaseForm needs to be transparent and have panel inside it 1/4 height of the form and should be opaque (which has some buttons and textbox). So I had set the transparent key to BackColor for the BaseFrom and for the panel I set it some other color.

For the rest of the area I need it to be transparent but capture events in the same, so i used another form(EventForm) to do so with opacity set to 1%. But on adding the EventForm as the child to the BaseForm the opacity value is over ridden by the parent form (BaseForm) which is opaque and I see a gray area. I cannot change the opacity of the base form as it also impacts the top panel.

Any suggestions?

pnuts
  • 58,317
  • 11
  • 87
  • 139
ramindar
  • 53
  • 5
  • 1
    Windows implements the hard rule that transparent windows are transparent to mouse clicks as well. They go to the underlying window, the one that the user sees. Using a low-level mouse hook to intercept the mouse events would be an alternative. Beware the user's utter bewilderment when clicks on a visible window no longer work. – Hans Passant Nov 01 '13 at 12:45

1 Answers1

0

It's very chancy that I've found there are many BackColors setting to which will make your form transparent and still clickable. One of those colors is Red, so you can try this:

public Form1(){
   InitializeComponent();
   BackColor = Color.Red;
   TransparencyKey = BackColor;
}

If you have other UI controls having red color, you may try other colors (as I said there are many colors working the same way). The point is I don't know why it works that way, just try and it works. Unbelievable, because as far as I know, the Opacity = 0 means click through.

King King
  • 61,710
  • 16
  • 105
  • 130
  • It seems of taking a benefit of a bug. But unfortunately i didnt work out for me :( – ramindar Nov 02 '13 at 08:44
  • @ramindar what version of .NET are you using? I'm using `.NET 3.5` – King King Nov 02 '13 at 08:59
  • @ramindar I've just tested in `.NET 4.5` and it also works OK, looks like it's not bug. If you like, I will send you the demo project to see it in action. – King King Nov 02 '13 at 09:01
  • @ramindar I really don't understand why it couldn't work for you, the code is simple enough to follow, here is the link to the `4.5 version` https://sites.google.com/site/thecabinet3/home/files-store/TransparentClient.rar?attredirects=0&d=1 – King King Nov 02 '13 at 13:45
  • i tried running your solution, but it doesn't work for me. I am able to click through the form and not able to capture events. having 4.5 version – ramindar Nov 04 '13 at 06:39
  • @ramindar what version of OS are you using? I'm using Windows 7 Ultimate, it's very strange. If it didn't work for you we still have another solution, BUT there are too much code, so you're stuck with it. Maybe the version of Windows is the cause. – King King Nov 04 '13 at 08:10