Question

Currently, I'm trying to have a top-level window in Windows Forms with a custom frame (using DevExpress' SkinManager.EnableFormSkins function) and still have a shadow around the window, when running on Windows 7 Aero.

The window currently looks like this:

enter image description here

and I want it to look like this:

enter image description here

(I.e. have a soft shadow around the window).

I did a lot of research and try-and-error, including using CS_DROPSHADOW, asking the DevExpress support, reading on SO, other blogs and MSDN documentation.

Still, nothing brings a shadow to my window.

Although I think that my requirement simply is not possible to achieve, I still want to take the chance and ask here on SO.

(I even thought of faking this by having a native Aero window behind my actual window but failed to implement...)

My question is:

Is it possible to have a window with a custom-drawn non-client (NC) area and still get a shadow around this window when Aero is active?

Was it helpful?

Solution 2

To summarize and close my own question, after much of an effort, I do think this is simply not possible.

What I achieved is to simulate a shadow by using the technique being used in the Locus Effects article.

Basically use a transparent window, dynamically use alpha blending PNGs as simulated shadow and draw that around the sides (and corners) of the window; move the transparent window, when the real window moves, etc.

This works well, but still looks kind of unprofessional to the user, because of small things like shadow disapears when other window is being activated not behaving as expected.

So my conclusion is: Not possible with a reasonable effort.

OTHER TIPS

Can you try custom win forms shadow like this:

/// <summary>
/// Base class for drop shadows forms.
/// </summary>
public partial class DropShadowForm : Form
{
    private const int CS_DROPSHADOW = 0x00020000;

    /// <summary>
    /// Creates new instance of DropShadowForm.
    /// </summary>
    public DropShadowForm()
    {
        InitializeComponent();
    }

    /// <summary>
    /// Overrides from base class.
    /// </summary>
    protected override CreateParams CreateParams
    {
        [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
        get
        {
            CreateParams parameters = base.CreateParams;

            if (DropShadowSupported)
            {
                parameters.ClassStyle = (parameters.ClassStyle | CS_DROPSHADOW);
            }

            return parameters;
        }
    }

    /// <summary>
    /// Gets indicator if drop shadow is supported
    /// </summary>
    public static bool DropShadowSupported
    {
        get
        {
            OperatingSystem system = Environment.OSVersion;
            bool runningNT = system.Platform == PlatformID.Win32NT;

            return runningNT && system.Version.CompareTo(new Version(5, 1, 0, 0)) >= 0;
        }
    }       
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top