views:

563

answers:

4

I tried the Visual C# Kicks code for an alpha-blended form. This works (as soon as I remove the TransparencyKey property); that is, I can use the W3C's PNG alpha test image and see other windows underneath, but makes all controls on the form invisible. Presumably, they simply aren't painted, as OnPaint is overridden. I tried calling the superclass's OnPaint:

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    UpdateFormDisplay()

    MyBase.OnPaint(e)
End Sub

, but this didn't change anything. (Calling MyBase.OnPaint first doesn't make any difference either.)

Unfortunately most articles about alpha-blended forms focus on pure splash screens without any controls on them — but we need a panel which first shows sign-in fields, then a progress bar.

The controls, by the way, do not need transparency; it's only on the outer edges that the PNG's transparency truly matters. So faking this by adding another form on top of this all (with the two always moving in tandem) might suffice, but I'd prefer a smoother solution.

+1  A: 

Try putting this in your form ctor after InitializeComponents();

base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

arul
A: 

Doesn't make a difference. The styles are applied (according to GetStyle), but I still don't see any controls.

I also tried using e.Graphics inside OnPaint to draw something manually, like:

e.Graphics.DrawString("Some text", New Font("Arial", 24, FontStyle.Regular), Brushes.Black, CSng(Me.Width / 2), CSng(Me.Height / 2))

, and it didn't show up either.

Sören Kuklau
+1  A: 

Strange, anyways, this article covers an alpha transformed form with controls:

http://www.codeproject.com/KB/miscctrl/AlphaForm.aspx

arul
A: 

That solution does essentially use the two-form trick, though: "holes" are cut into the translucent form; the form underneath then can have controls at those spots.

In any case, while far form an elegant solution this appears to work well enough. Thanks!

Sören Kuklau