Member Avatar for nssltd

Okay hi,

Firstly i have a border less which i need as i have my own custom 'skin'
which looks like this and is found here.http://i51.tinypic.com/2i77o94.png
As you can see it has no drop shadow at all. What i want to achieve is for it to have a drop shadow much like this http://i54.tinypic.com/hrk5l0.png

i know all about the create param's method i even posted a snippet on it

private const int CS_DROPSHADOW = 0x20000;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }

However this only gives me a very small shadow and only on the bottom and right sides of the form. I'd like a four sided shadow which was considerably larger than the create params method. As far as i know create param's cannot be modified to produce a larger shadow.

I've heard that i might be able to achieve this through layered windows?

Thanks for any help you can give me on this issue. Links, code or pointers.

NSSLTD

Recommended Answers

All 3 Replies

Member Avatar for nssltd

hi, check here.

Thanks for the post, it does look like what i want to do and we've both tried similar methods and would like to avoid wpf.

However i'm not a member of this site and you have to pay to see the solution.
Also i cannot access the free trial without having to pay. :(

Use a separate form that is borderless as well and has an Opacity of .5. Make it slightly bigger than the main form. You can make the "drop shadow" invisible to clicks by using a combination of WS_EX_NOACTIVATE and WS_EX_TRANSPARENT in the CreateParams() function. Simply move the drop shadow whenever the main form moves.


check this code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        DropShadow ds = new DropShadow();

        public Form1()
        {
            InitializeComponent();
            this.Shown += new EventHandler(Form1_Shown);
            this.Resize += new EventHandler(Form1_Resize);
            this.LocationChanged +=new EventHandler(Form1_Resize);
        }

        void Form1_Shown(object sender, EventArgs e)
        {
            Rectangle rc = this.Bounds;
            rc.Inflate(10, 10);
            ds.Bounds = rc;
            ds.Show();
            this.BringToFront();
        }

        void Form1_Resize(object sender, EventArgs e)
        {
            ds.Visible = (this.WindowState == FormWindowState.Normal);
            if (ds.Visible)
            {
                Rectangle rc = this.Bounds;
                rc.Inflate(10, 10);
                ds.Bounds = rc;
            }
            this.BringToFront();
        }

    }

    public class DropShadow : Form
    {

        public DropShadow()
        {
            this.Opacity = 0.5;
            this.BackColor = Color.Gray;
            this.ShowInTaskbar = false;
            this.FormBorderStyle = FormBorderStyle.None;
            this.StartPosition = FormStartPosition.Manual;
        }

        private const int WS_EX_TRANSPARENT = 0x20;
        private const int WS_EX_NOACTIVATE = 0x8000000;

        protected override System.Windows.Forms.CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE;
                return cp;
            }
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.