1

I am trying to apply a dropshadow for the bordeless winform from a component by overriding its CreateParams function but I'm getting an exception "no suitable method found to override" within the component.

How best can I apply a borderless WinForm's dropshadow from a component or is it possible to do so?

I can apply a dropshadow within the form itself but creating a component will make it easy to reuse the code.

I am trying to achieve this in winform using c#.

Russell Chidhakwa
  • 339
  • 2
  • 5
  • 16
  • 1
    By the time the component is created the `Form` object already exists (CreateParams has been called). You could do this as a `Form` that you inherit your others forms from. `public class MySuperSpecialForm : DropshadowForm {...}` – Sam Axe Oct 22 '19 at 23:20
  • 1
    Can the dropshadow effect be set with Win32 Window Styles (e.g. `SetWindowLong()`)? – Sam Axe Oct 22 '19 at 23:21
  • 1
    You can't "hook" a protected virtual method. Only alternative is to create a dedicated Form-derived class so it can co-operate in its CreateParams override, but then you don't really need that component anymore. – Hans Passant Oct 22 '19 at 23:28
  • Okay. I thought I was missing something. I appreciate all your clarifications. – Russell Chidhakwa Oct 23 '19 at 04:08
  • @Sam: I will try that – Russell Chidhakwa Oct 23 '19 at 04:17
  • @Hans: I appreciate your clarification. I will try your approach as well. Better now that I know why I'm getting the error. Thank you. – Russell Chidhakwa Oct 23 '19 at 04:18
  • @Sam: I just tried your advice. It worked. Creating a Form and then inheriting all my other winforms from it. I really appreciate your helpful approach. – Russell Chidhakwa Oct 23 '19 at 04:31
  • @Hans: I created a Form-derived class and it worked. Thank you all for saving me time by offering the best approach. – Russell Chidhakwa Oct 23 '19 at 04:35

0 Answers0