Help with Opacity and TransparencyKey

B

Brian

If your like me, you have probably seen way too many demos of the opacity
property of a form. Well I finally have a need for it and I am having an
issue.

I am trying to create a splash screen that looks like Adobe Acrobat's which
appears to draw outside its bounds. To do this, I am setting the
Transparency of the SplachScreen form to its background color and then
drawing my screen (which appears to have no background). It looks really
cool but I now want the screen to fade out on close. To do this I am slowly
changing the opacity of the form. Now for the issue:

As the opacity changes the background color is also changed and no longer
matches the TransparencyKey which results in the form being visible during
the fade out. How can I fix this? Is there a way to calculate the
resulting color of after opacity transformation?

Thanks,

Brian


Private Sub SplashScreen_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TransparencyKey = Me.BackColor
Dim DelayedCloser As New Closer(AddressOf DelayedClose)
DelayedCloser.BeginInvoke(Nothing, Nothing)
End Sub

Private Sub SplashScreen_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.FillRectangle(Brushes.Khaki, New Rectangle(100, 0, 300,
200))
e.Graphics.DrawString("Logo", New Font("Arial", 36, FontStyle.Bold,
GraphicsUnit.Pixel), Brushes.Navy, 105, 10)
e.Graphics.DrawLine(Pens.Navy, 0, 50, 200, 50)
e.Graphics.DrawLine(Pens.Navy, 25, 55, 200, 55)
e.Graphics.DrawLine(Pens.Navy, 50, 60, 200, 60)
End Sub

Private Delegate Sub Closer()

Private Sub DelayedClose()
Threading.Thread.CurrentThread.Sleep(2000)
For o As Double = 1.0 To 0.0 Step -0.1
Me.Opacity = o
Threading.Thread.CurrentThread.Sleep(10)
Next
Me.Close()
End Sub
 
B

Brian

Changing the background color of the form to white fixes the problem (white
is not effected by the opacity).

I would still like to know how to calculate the resulting color after
opacity is changed. If anybody out there knows, please let me know.
 

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