Translucent forms and property grids

J

jarnie

I am attempting to make a form which has alpha transparency that
varies across the form, similar to the Adobe splash screens and
launchy:
http://www.launchy.net/images/screenshot_sheep.jpg

After a few different approaches, I have ended up overriding the
OnPaint method and using Graphics.CopyFromScreen and then painting the
transparent PNG on top of this using DrawImage. I have so far been
able to get the same effect when stationary, but there are 2 issues:

(1) As you drag the form, there is a slight delay between the form
being moved and the background being drawn. With launchy, the effect
is fluid and there is no delay.

(2) If the content behind the form changes it doesn't show. Is there
any way to trigger a repaint when any forms behind my form change (or,
is there a better way of doing what I am attempting to do)?

Any help please? I have had a look at the 'Vista' form on CodeProject,
which appears to be ideal - but I don't know C# and don't have a
compiler to see if the effect is in fact what I would like to achieve.

----------
Additionally, is it possible to reset all the GridItems within a
PropertyGrid to be reset, without recursively looping through each
item? I know of PropertyGrid.ResetSelectedProperty, but doesn't this
mean I'd have to select each item individually and reset it?

Finally, is it possible to deselect the current property? I tried
using PropertyGrid.SelectedGridItem = Nothing, but it throws an
error.


Thank you very much in advance,
James
 
R

rowe_newsgroups

Any help please? I have had a look at the 'Vista' form on CodeProject,

What's the URL for the article?
but I don't know C#

Actually, C# is very similar to VB.Net, you just need to get used to
the different syntax. Here's a URL that should explain some of the
differences:

http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html
and don't have a compiler to see if the effect is in fact what I would
like to achieve.

Sure you do, you probably just don't realize it. The compilers
for .Net languages actually ship with the framework, not visual
studio, so if you have the framework installed (which I'm sure you do
if your programming in VB.Net right now) you have the compiler. The
only thing you need to figure out is how to compile with the command
line arguments - a quick Google search should turn this info up.

By the way, the compiler's default directory for 2.0 is C:\WINDOWS
\Microsoft.NET\Framework\v2.0.50727\csc.exe

Thanks,

Seth Rowe
 
J

jarnie

What's the URL for the article?


Actually, C# is very similar to VB.Net, you just need to get used to
the different syntax. Here's a URL that should explain some of the
differences:

http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html


Sure you do, you probably just don't realize it. The compilers
for .Net languages actually ship with the framework, not visual
studio, so if you have the framework installed (which I'm sure you do
if your programming in VB.Net right now) you have the compiler. The
only thing you need to figure out is how to compile with the command
line arguments - a quick Google search should turn this info up.

By the way, the compiler's default directory for 2.0 is C:\WINDOWS
\Microsoft.NET\Framework\v2.0.50727\csc.exe

Thanks,

Seth Rowe

Thanks for the reply.

The URL is: http://www.codeproject.com/useritems/How_to_make_VistaForm.asp

Since posting I have downloaded C# EE and had a look. However, it is
not the same as launchy - in fact it has the same issues I am having.
"Jumpy" updates as you drag it, plus it doesn't account for any
changes behind the window.

As such, does anyone know any better way of doing this, or how launchy
does it? I believe it is written in C, the source can be downloaded
from sourceforge if anyone is interested.

Finally - any pointers with the PropertyGrid questions? Thank again,
James
 
J

jarnie

Thanks for the reply.

The URL is:http://www.codeproject.com/useritems/How_to_make_VistaForm.asp

Since posting I have downloaded C# EE and had a look. However, it is
not the same as launchy - in fact it has the same issues I am having.
"Jumpy" updates as you drag it, plus it doesn't account for any
changes behind the window.

As such, does anyone know any better way of doing this, or how launchy
does it? I believe it is written in C, the source can be downloaded
from sourceforge if anyone is interested.

Finally - any pointers with the PropertyGrid questions? Thank again,
James

Update: I've managed to solve the transparency problem. I can now draw
a semi-transparent form with alpha transparency that varies across the
form (using a PNG). After a good few hours searching & reading I came
up with some important searches: UpdateLayeredWindow and Per-Pixel
Alpha Blending. The following code loads a PNG and applies it to the
form, allowing you to see through it, drag it around & it updates as
smooth/quick as dragging a normal window. It even updates when things
behind it change. Note that this was from the (very) useful article:
http://www.codeproject.com/gdi/pxalphablend.asp

Now, however, I have a new issue! Any controls that were on the form
are no longer visible. I had a textbox, picturebox and label - all of
which are gone. It I remove the CreateParams part they reappear, but
the window is no longer transparent.

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC
As Integer) As Integer
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As
Integer) As Integer
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject
As Integer) As Integer
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal
hWnd As Integer) As Integer
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As
Integer, ByVal hDC As Integer) As Integer
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As
Integer, ByVal hObject As Integer) As Integer
Private Declare Function UpdateLayeredWindow Lib "user32" (ByVal
hWnd As IntPtr, ByVal hDCDst As IntPtr, ByRef pptDst As Point, ByRef
pSize As Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Point, ByVal
crKey As Integer, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As
Integer) As Boolean

Private Structure BLENDFUNCTION
Public BlendOp As Byte
Public BlendFlags As Byte
Public SourceConstantAlpha As Byte
Public AlphaFormat As Byte
Public Sub New(ByVal _BlendOp As Byte, ByVal _BlendFlags As
Byte, ByVal _SourceConstantAlpha As Byte, ByVal _AlphaFormat As Byte)
BlendOp = _BlendOp
BlendFlags = _BlendFlags
SourceConstantAlpha = _SourceConstantAlpha
AlphaFormat = _AlphaFormat
End Sub
End Structure

Public Sub SetBackgroundImage(ByVal theImage As Bitmap)

Dim screenDc As IntPtr = GetDC(IntPtr.Zero)
Dim memDc As IntPtr = CreateCompatibleDC(screenDc)
Dim hBitmap As IntPtr = IntPtr.Zero
Dim oldBitmap As IntPtr = IntPtr.Zero

Try

hBitmap = theImage.GetHbitmap(Color.FromArgb(0))
oldBitmap = SelectObject(memDc, hBitmap)

UpdateLayeredWindow(Me.Handle, screenDc, New
Point(Me.Left, Me.Top), theImage.Size, memDc, New Point(0, 0), 0, New
BLENDFUNCTION(0, 0, 255, 1), 2)

Finally

ReleaseDC(IntPtr.Zero, screenDc)

If Not hBitmap.Equals(IntPtr.Zero) Then
SelectObject(memDc, oldBitmap)
DeleteObject(hBitmap)
End If

DeleteDC(memDc)

End Try

End Sub

Protected Overrides ReadOnly Property CreateParams() As
CreateParams
Get

Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H80000
Return cp

End Get
End Property


Question: How can I have a transparent window but with controls on it?
If this isn't possible, what is the best way to show a transparent
background and overlay the controls ontop?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top