Results 1 to 12 of 12

Thread: Can I write or draw on transparent form?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2000
    Posts
    1,463

    Can I write or draw on transparent form?

    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?

    Thanks,

    Warren

  2. #2
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Can I write or draw on transparent form?

    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.

  3. #3
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Can I write or draw on transparent form?

    Hey WarrenW,

    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.
    Attached Files Attached Files
    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]

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Can I write or draw on transparent form?

    @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.

    Attached Files Attached Files

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Can I write or draw on transparent form?

    Was what I suggested what you were aiming for? Or something different?

  6. #6
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Can I write or draw on transparent form?

    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...

  7. #7
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Can I write or draw on transparent form?

    Hey Bushmobile,

    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]

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Can I write or draw on transparent form?

    Cheers for the comments guys

    Quote Originally Posted by Keith_VB6
    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.

    I'll whip up a better version at some point.

    Quote Originally Posted by Keith_VB6
    A bit like drawing on glass
    i like that - I'll call it a glass form

  9. #9
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Can I write or draw on transparent form?

    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]

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Can I write or draw on transparent form?

    I finally got round to writing a better version of this code.

    If you're interested then it's in the CodeBank

  11. #11
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Can I write or draw on transparent form?

    Pretty neat. Great interface. I love those round min,max buttons.
    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]

  12. #12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width