What i want to do is make the form transparent but then be able to type on it and have it show. The problem is if you make it transparent, any key or mouse activity will take place on the program behind it. Is there a method I am not thinking of?
The problem with transparent forms (as you've found out) is that you can't access them once they're transparent. There are 2 solutions though.
1) Make a small section of your form opaque, and add code so that alternate clicks on this section will toggle the whole form between opaque/transparent. I've no code for this, as I use :-
2) Add a system tray icon with the opaque/transparent menu options - or even a config form which transfers data to the transparent form.
If anyone can think of other methods, please let me know!
BTW, if you decide to use (1), could you please post the code?
EDIT:-
I've just thought of a 3rd, very cr*p, way. You could have your prog detect when the mouse is in a corner of the screen, and after say 3 seconds toggle it between states.
Last edited by schoolbusdriver; Jun 13th, 2006 at 03:24 PM.
As long as the form has focus, then it will still receive keyboard input.
If the form is transparent it will still receive mouse moves, unless parts are completely "masked" or "cut out" with SetWindowRgn().
You could still use GetCursorPos() in a timer. But with nothing to click, what would be the point ?
FYI... I don't know what code you're using. But a from can be transparent, you can use a "mask color" and everything but that color is painted or you can make a form transparent with a "mask color." Or even cut out with SetWindowRgn().
I've attached a short demo project that shows various transparency styles. For you and anyone else who might be interested. It's just some quick code, but it gets the point across.
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
@Keith_VB6: if you use SetLayeredWindowAttributes and set a form's alpha or colorkey to 0 then any mouseclicks will pass straight through.
You can set a form to an alpha transparency of 1 and to all intents and purposes it is invisible, but it will still receive mouse events - however anything you put on it will be equally invisible.
You can also just make parts of your form transparent using the ColorKey, but then these are either transparent or opaque, there's no in between - and any mouseevents of these parts will be lost if they are transparent.
I think the solution is to have two forms, one with a very low alpha on top of one with a colorkey transparent. you can then catch the events on the top form and draw whatever on the bottom.
I've attached a proof of concept example - it's only very basic. There's a rather clumsy select case construct to allow you to press the button - this could be replaced with a neat sub that loops through the controls on form2 if need be.
If anyone can think of other methods, please let me know!
It works for me bushmobile. Putting a textbox on Form2, setting its backcolor (to vbCyan) and using Form2.SetFocus in MouseDown, allows you to tab around (+ type in the textbox). Unless there's dozens of controls, you can just tab to the Close button. The mouse works in the textbox after it's got the focus. Nice method with little code and easy to build on.
Over to WarrenW.
Last edited by schoolbusdriver; Jun 14th, 2006 at 02:13 PM.
Reason: Clarification...
I looked at your project. That's pretty a neat idea. A bit like drawing on glass. We'll have to wait and see if that's what WarrenW is looking for.
One idea though. Form2 had the control on it and is masked ( color keyed ) What if it was set to be always-on-top? Then, it wouldn't be necessary to pass the events. The controls would sort of float over the other form. And when the transparent part is click, focus goes straight to Form1. Form1's focus could also be set through code.
Then, just link the 2 forms events together. I.E. resizing one would cause the other to be the same size, minimize one and they both minimize. ETC...
WarrenW, does Bushmobile's example do what you want to do ? If not, let us know.
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]
One idea though. Form2 had the control on it and is masked ( color keyed ) What if it was set to be always-on-top? Then, it wouldn't be necessary to pass the events. The controls would sort of float over the other form. And when the transparent part is click, focus goes straight to Form1. Form1's focus could also be set through code.
You're saying have the alpha'd form always under the colourkeyed form, yeah? I did think about doing that at the time - the only problem is that as soon as you've drawn on the colourkeyed form it receives the events.
e.g. I click a transparent place in the form(s) - the mousedown event passes through the colourkeyed form onto the alpha'd form. This then causes colour to be drawn on the colourkeyed form. The mouse is now over a non-transparent part of the colourkeyed form, so all the events will be passed to that instead - interrupting what we were doing.
I think the best way is to monitor the mousemove event - check if it's over any controls or not - and moving the focus accordingly.
Yeah, bushmobile. I see what your saying. We'll just have to see it it's what WarrenW is trying to do. BackStyle=vbGlass
I'll probably be playing with your code myself. I was thinking about using regions. It would be simple with buttons. Just loop through each button and assign the coordinates to a region. Although, it might be easier to just add a Popup menu.
It'll be interesting to see what comes out of this.
Keith_VB6
If you have any further questions, just ask.
If this solves things, then please mark the thread resolved.
[Thread Tools] --> [Mark Thread Resolved]