This is a migrated thread and some comments may be shown as answers.

Truly Transparent Shaped Form

4 Answers 497 Views
ShapedForm
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 02 Nov 2012, 01:08 PM
I've already read this post:  http://www.telerik.com/community/forums/winforms/forms-and-dialogs/transparent-background-for-rad-shapedform.aspx   It is close, but not quite what I need.

How do we use a PNG file with tranparency to make a truly transparent form?  Any time I try this, truly empty areas in the PNG work fine, but partially transparent areas (like shadows) are underlayed with the "transparent" color.

I've attached three images:
- Screenshot of the intended effect.  (The welcome/splash screen from Visual Studio.)
- Screenshot of setting the shaped form control background and transparent color to blue with my transparent PNG as the background.
- The form background image I am using to test.

Any help you can offer is greatly appreciated.

Thanks,

- Brad

4 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 07 Nov 2012, 01:10 PM
Hello Brad,

Thank you for writing.

The scenario is not possible to achieve in all cases due to the native windows implementation which causes some rendering issues when the transparent window is repainted. This is related for all Forms (including Microsoft Form control).

I hope that you find this information useful.

Regards,
Svett
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Brad
Top achievements
Rank 1
answered on 07 Nov 2012, 08:52 PM
I'll continue to look; someone knows how to do this.  There are too many applications (including Visual Studio) with transparent splash screens.

It seems this would be a prime candidate for a feature to add to the shaped form control.

Thanks for your reply.
0
Accepted
Svett
Telerik team
answered on 12 Nov 2012, 03:13 PM
Hi Brad,

As a starting point of your research you can use the following approach:

public partial class TransparentShapedForm : ShapedForm
    {
        public TransparentShapedForm()
        {
            InitializeComponent();
 
            this.FormBorderStyle = FormBorderStyle.None;
            this.StartPosition = FormStartPosition.CenterScreen;
        }
 
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= NativeMethods.WS_EX_TRANSPARENT;
 
                return cp;
            }
        }
 
 
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            // Don't paint background
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
            Image image = this.BackgroundImage;
 
            if (image == null)
            {
                return;
            }
 
            Graphics graphics = e.Graphics;
 
            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 
            graphics.DrawImage(image, Point.Empty);
        }
    }

Notice that the code above has some glitches when the form is overlapped by another form. If you can rid of them, you will complete your scenario. It seems that the windows messages and rendering do not deal well with the custom form. The glitches occur with the standard Form and ShapedForm and are not related to the Telerik products. All the best,
Svett
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Accepted
Brad
Top achievements
Rank 1
answered on 12 Nov 2012, 03:21 PM
http://www.codeproject.com/Articles/1822/Per-Pixel-Alpha-Blend-in-C

For anyone else trying the same thing, I grabbed code from the link above and incorporated that into my form to accomplish what I needed.

Tags
ShapedForm
Asked by
Brad
Top achievements
Rank 1
Answers by
Svett
Telerik team
Brad
Top achievements
Rank 1
Share this question
or