none
Possible to Panel with Drop Shadow in C# Windows Form..?

    Question

  • Hi All

    Can Possible to Panel with Drop Shadow in C# Windows Form

    with Best Regards


    • Edited by Himaxnaz Thursday, December 7, 2017 12:58 PM simple
    Wednesday, December 6, 2017 9:55 PM

All replies

  • Just use WPF and it will make your life much easier
    Thursday, December 7, 2017 1:36 AM
  • Hi Himaxnaz,

    Try this:

    Transparent drop shadow in C# (GDI+ and Windows Forms)

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 7, 2017 5:51 AM
  • Hello Himaxnaz,

    Please tell me your program type, Wpf,Winform,Uwp or others? The feature in different program type have different ways to achieve.

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 7, 2017 6:05 AM
    Moderator
  • thanks
    Thursday, December 7, 2017 12:59 PM
  • Sorry

    i am using C# Windows Form

    beast Regards


    • Edited by Himaxnaz Thursday, December 7, 2017 1:01 PM simple
    Thursday, December 7, 2017 1:00 PM
  • Hi Himaxnaz,

    Also try this:

    Create a class named MyShadowPanel inherited Panel:

        class MyShadowPanel : Panel
        {
            [DllImport("user32.dll")]
            static extern IntPtr GetWindowDC(IntPtr hWnd);
            [DllImport("User32.dll")]
            static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
    
            public MyShadowPanel()
            {
                this.BorderStyle = BorderStyle.Fixed3D;
                this.Paint += ParentPaint;
            }
    
            protected override void WndProc(ref Message m)
            {
                const int WM_NCPAINT = 133;
                if (m.Msg == WM_NCPAINT)
                {
                    IntPtr hdc = GetWindowDC(m.HWnd);
                    Graphics g = Graphics.FromHdc(hdc);
                    Rectangle rDraw = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                    Pen pBottom = new Pen(Color.Gray, 3);
                    Pen pTop = new Pen(Color.White, 3);
                    g.DrawRectangle(pBottom, rDraw);
                    Point[] pts = new Point[3];
    
                    pts[0] = new Point(0, this.Height - 1);
                    pts[1] = new Point(0, 0);
                    pts[2] = new Point(this.Width - 1, 0);
    
    
                    g.DrawLines(pTop, pts);
                    ReleaseDC(this.Handle, hdc);
                }
                else
                {
                    base.WndProc(ref m);
                }
            }
    
            private void ParentPaint(object sender, PaintEventArgs e)
            {
                Graphics g = this.Parent.CreateGraphics();
                Matrix mx = new Matrix(1F, 0, 0, 1F, 4, 4);
                Rectangle rdraw = new Rectangle(this.Left, this.Top, this.Width, this.Height);
                g.Transform = mx;
                g.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.Black)), rdraw);
                g.Dispose();
            }
        }

    Run your project then close it.

    You can find there is a control named MyShadowPanel in the Toolbox, then drag it to your form:

    Hope this helps!

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 8, 2017 1:22 AM