Clearly, the most visible part of
the Overlay project is the overlay itself. If you take a look at the
picture to the right, you will see that Overlay is actually a semi-transparent
form that covers the user's regular desktop. In this semi-transparent form are
the various widgets the Overlay user has configured for use. These
widgets are not transparent at all.
My initial thoughts were to create a WinForm, set its Opacity to some value less
than 100%, and be off and running. Unfortunately, as anyone that has
played with WinForms knows, its not that simple. What is the
problem? Well, it turns out that when a WinForm has it's opacity set to
some value less than 100%, all of the controls on the form inherit this opacity
as well. To add insult to injury, there does not appear to be any way to
control the opacity of individual controls. Since semi-transparent
controls are hard on the eyes, using Opacity was not the way to go.
I did some additional research and came across the
native Win32 Layered Windows stuff. I played around with it briefly but
came aware with impression that is doesn't solve the core problem of controls
inheriting the opacity of the parent form. Maybe if I had dug into it
more I would have found something else, but since this is a hobby project and I
wanted to make some progress, I pressed on.
What I decided to do was basically put a new twist on the code provided in
Billy Hollis' ChalkTalk Application. Using two WinForms, layer a
transparent WinForm on top of another WinForm that has an opacity value of
75%. You can see what I mean be looking at the picture to the left.
Why do I need to use two
WinForms? If you read Billy's article, you will see that I am
accomplishing two things. First, the transparent WinForm will be used to hold
all of the Overlay's widgets. WinForm controls do not inherit the parent
form's transparency setting, so any controls added to the transparent WinForm
will be completely visible to the end user. One thing to remember, however, is
that transparent WinForms do not process click events. This does not
apply to the children controls (which are not transparent), but it does raise
problems if we want to have things like right-click context menus.
The bottom WinForm provides Overlay with two things. Most obvious is that it
provides the semi-transparent overlay on the user's desktop. The other is
that it will act as an "event detector" for any events that we would normally
want to capture on the transparent form. You can find a sample project
that shows how these forms are used here. There may well be other ways of doing
this, but for now that is what I am going with. If you know of a better
solution, drop me a line. I have spent very little time looking at this
and researching alternatives.
So what will this look like in the app? The startup form for the app will have its Opacity set to 75%. In it's Load event, it will create a new form, Overlay, that has its TransparencyKey set to Magenta and the Background color also Magenta (making it completely transparent). The Main form will then Show the Overlay form. Both forms will have their default size set to Maximized.
Up next - detecting and acting on hot keys.