All over control transparency

BristolMatt

Member
Joined
Sep 11, 2006
Messages
6
Programming Experience
3-5
Hi
I am looking to create a set of transparent controls to fade-in/fade-out like a cross between a tooltip and the info boxes that appear in your text in word. The effect I want is like the popup mail messages in Outlook 2003.

One way I can do this is by creating a form adding the controls to it and then adjusting the opacity of the form. However when the user hovers over text box that initiates this popup, clicks the popup, moves over the popup etc, the focus transfers from the parent form - a tad distracting. I have tried re-activating this parent form but with no sucess.

Next I abandoned the form approach and added a panel with the following line in New()
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
but it only adjusts the back colour and not any background images etc.

Any ideas on how to create a control that has transparency like the opacity of forms or how to add a form that does not take focus would be great.

Cheers
 
Override the WndProc of your 'popup' form and add the following

VB.NET:
Const MA_NOACTIVATE = 3
 
If m.msg = &H21 then
m.result = new intptr(MA_NOACTIVATE)
end if
Mybase.wndproc(m)



N.B it is possible to re-activate the form, you will need the sendmessage api, and the WN_NCACTIVATE
constant. Something like this, but can't be sure of the code as it's from memory

VB.NET:
<DllImport("User32.Dll")> _
Public Shared Function SendMessage(ByVal Handle as intptr, byval msg as integer, byval lParam as integer, 
byval wParam as intptr)
to use..

VB.NET:
SendMessaage(form.handle, WM_NCACTIVATE, 1, intptr.zero)
However my example using the wndproc is far easier for this scenario.
 
Ah, my mistake it should have been this...

VB.NET:
Const MA_NOACTIVATE = 3

If m.msg = &H21 then
m.result = new intptr(MA_NOACTIVATE)
else
Mybase.wndproc(m)
end if

Note though that this wont work if you have the TopMost property set to true
 
Still no luck with it. I have added me.topmost = false to New() too.
I have a timer that increments the opacity value as the popup fades in. This wouldn't be causeing problems would it?
 
Quite possibly. I have tested this out and if you use .show or .show dialog then the form will steal the focus.

Rather than using a timer you can do it this way. Add this to your popup class.

VB.NET:
<DllImport("user32")> _
Public Shared Function AnimateWindow(ByVal hwnd As IntPtr, ByVal time As Integer, 
ByVal flags As Integer) As Boolean
End Function
 
Friend Sub ShowPopup()
AnimateWindow(YourPopup.Handle, 200, 524288)
End Sub


This code will use the built in fade function of the win32 API. Use my code above and it won't steal the focus, you also dont have to mess around with timers and such.

EDIT: Just had to alter the last parameters of the API call to integer.
 
They are not in there. It's a set of constants. If you look at my last post i have added an edit that changes the last parameter of the API call to integer.
 
VB.NET:
Public Enum AnimationFlags As Integer
AW_ACTIVATE = 131072
AW_BLEND = 524288
AW_CENTER = 16
AW_HIDE = 65536
AW_HOR_NEGATIVE = 2
AW_HOR_POSITIVE = 1
AW_SLIDE = 262144
AW_VER_NEGATIVE = 8
AW_VER_POSITIVE = 4
End Enum

Thats all the AnimationFlags, at the moment you are using AW_BLEND. All the rest are for sliding left, right, forward diagonal etc. I've never tried fading it out. You could try using the same function again maybe. If that doesn't work you can try AW_HIDE. Like i say though i've never tried fading it out so i don't know for sure.
 
Back
Top