Click here to Skip to main content
15,891,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In advance thanks for spending time for reading this question and helping me.

Let's say I have a program with 10 windows forms. now I want them all to have a specific unique function, I don't want to rewrite it 10 times, I'd like to put the function in a class and then other classes can have that function in their implementation.

What I have tried:

Currently I'm searching for it and yet I have no idea about it.
Posted
Updated 15-Jul-16 21:27pm

1 solution

The easiest way if to create a new class based on Form:
C#
public class MyForm : Form
   {
   ...
   public string MethodAvailableInAllDerivedClasses(string parameter)
      {
      ...
      }
   ...
   }
And then change all your "real" forms to derive from that instead of directly from Form.
 
Share this answer
 
Comments
m.r.m.40 16-Jul-16 3:48am    
Yes it worked.
thanks,
Now the only question that remains is how to do that using usercontrols?
OriginalGriff 16-Jul-16 3:56am    
Sorry?
That doesn't make any sense to me - remember that we can't see your screen, access your HDD, or read your mind: we only get exactly what you type to work with, we don't get any of the context that you assume about the project.
So explain where UserControls fit into this exactly and why they cause you a problem.
m.r.m.40 16-Jul-16 4:05am    
I'm sorry,
Let's say it's an application with 10 forms and 10 usercontrols.
I could make all forms to inherit from a base class and include the functionality I want, but the usercontrols cannot have that functionality inside themselves, I'll post this problem as a new question and link it here, because it's going to be a different question.
BillWoodruff 16-Jul-16 8:03am    
"the usercontrols cannot have that functionality inside themselves, "

why is that ?
OriginalGriff 16-Jul-16 8:21am    
I'm assuming because it affects the form the UC is embedded into, and that's a no-no from an OOPs POV.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900