Simple implementation of C bezel shading effect for an unbordered form

  • 2020-05-19 05:35:08
  • OfStack

Call the method SetShadow() in the constructor with the following code;

You can achieve the shadow effect of the borderless form

You need to add the namespace using System.Runtime.InteropServices;


private const int CS_DropSHADOW = 0x20000;
        private const int GCL_STYLE = (-26);        
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);    

        private void SetShadow()
        {
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); 
        }


Related articles: