0

I try to add shadow around Form So I put this in my form code:

 protected override CreateParams CreateParams
        {
            get
            {
                const int CS_DROPSHADOW = 131072;
                CreateParams cparams = base.CreateParams;
                cparams.ClassStyle = CS_DROPSHADOW;
                return cparams;
            }
        }

it work perfect but when i click on parent form by mistake the shadow remove and i can't return it back how can i fix it?

  • I dont think the problem is in this override... How can we reproduce your problem? – Sievajet Jan 01 '18 at 15:10
  • You mean a borderless form? Can't you show it with `SomeForm.ShowDialog(this)`? Anyway, look at [Drop Shadow On A Borderless WinForm](https://stackoverflow.com/questions/16493698/drop-shadow-on-a-borderless-winform). BTW, you should `cparams.ClassStyle |= CS_DROPSHADOW;` – Jimi Jan 01 '18 at 15:17
  • @Jimi I'm using 'SomeForm.ShowDialog(this)' to call my form the problem here if i click out of form the shadow will Disappears and will not come back again i try this 'cparams.ClassStyle |= CS_DROPSHADOW;' the same problem – Abd ul rahaman Shalata Jan 01 '18 at 16:35
  • See if this one helps [DropShadow for WPF Borderless Window](https://stackoverflow.com/questions/3372303/dropshadow-for-wpf-borderless-window). The question tags WPF, but for this should be the same (I haven't tested it though). – Jimi Jan 01 '18 at 17:25
  • It is specific to the code that is not in the question. Either ShowDialog() or Show(owner) causes the drop-shadow to disappear. Smells like a Win10 specific issue. No workaround that I can think of, other than displaying it non-modal and non-owned with plain Show(). – Hans Passant Jan 01 '18 at 18:38
  • @Hans Passant I was thinking about sending a PostMessage WM_Paint to the owner. It should redraw, since here the problem is that the (external) shadow is not redrawn. – Jimi Jan 01 '18 at 19:01
  • Well, if in the Activated event of `SomeForm` you send a `PostMessage` to the caller Form, the shadow is redrawn. Pass the handle of the caller with `Form SomeForm = new SomeForm(this.Handle);`, then use the handle to PostMessage with Msg=WM_Paint. It does redraw that shadow (at least the caller Form does). – Jimi Jan 01 '18 at 19:12
  • @Jimi where i should add this code? – Abd ul rahaman Shalata Jan 02 '18 at 12:15
  • 1
    Which part? Are you familiar with P/Invoke methods? I think the best thing you can do here, if you really need a borderless form, as @Hans Passant said, is to just `.Show(this)` the new form, since `.ShowDialog()` would revert the behavior back to normal. – Jimi Jan 02 '18 at 14:07

0 Answers0