C # Apply interface to form class

How can I apply an interface to a form class

partial class Form1 : Form, InterfaceA

      

Is it correct?

Basically, I would like to implement an interface on a form. How to ...

+1


source to share


3 answers


Form is just a class (they are subclasses of System.Windows.Forms.Form), so yes - the standard syntax is fine, as is yours.

Edit. Regarding the partial part of the question, no, you only need to declare that you are implementing the interface once. From MSDN ...



If any part is declared abstract, then the entire type is considered abstract. If any of the parts is declared leakproof, then the entire type is considered leakproof. If any part declares a base type, then the entire type inherits that class.

Remember, there is no magic in forms or partial classes. C # /. NET is one of the few Microsoft projects that has no magic - it really behaves the way you think it is.

+6


source


Yes - form is just class at the end of the day



+1


source


When working with partial classes in C #, either:

  • any declaration with the ':' operator must specify the exact same base class and interfaces
  • specifying the base class and interfaces on one of the declarations will suffice

To make life easier for yourself, add the interface specs in only one place (no validation, I suspect this refers to the default constructor class part when working with the WinForms designer).

0


source







All Articles