Click here to Skip to main content
16,020,347 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

I have a problem with my .NET C# window from project.
I have many different window forms in my project, and many of them looks similar.

Currently, I create individual control items and code for each window from.
That means, I need to modify the UI design and the source code many times whenever I have bugs or I need to implement new features. I need to repeat the coding work many times! That makes me really tired.

Is there a way to implement the UI design only once and share it between window forms?

Please feel free to contact me if you have any question. Thank you!

Eric Fang

What I have tried:

I try to implement some global functions to improve this, but it does not help too much.
Posted
Updated 4-Jan-18 23:37pm

1 solution

That's complicated, because we can't see your forms, or get any feel for what they do, or how much "similarity" there actually is.

But if you have the same code in multiple places, there are a couple of ways you can reduce that.
The first way is to declare a "base form" which implements the shared functionality, and derive your other forms from that. That way, you modify the common code and controls once, and it automatically "propagates" to the derived forms.

The second way is to look closely at what you are duplicating and abstract that into UserControls which you reuse across a number of forms. Again, this means that you have a single code base which you can modify and which updates all the forms using it.

I use UserControls quite a lot, both to "share" common control functionality and appearance, and to "compartmentalise" my code and make the form code base smaller and easier to work with.

What's good for you? Dunno - we don't have any access to your app!
 
Share this answer
 
Comments
Yu-Long Fang 5-Jan-18 5:55am    
Hello, OriginalGriff,

I think UserControls might be a good idea.
I have never used that before. I will try to figure that out. Thank you!

Eric
OriginalGriff 5-Jan-18 6:09am    
You're welcome!
Ralf Meier 5-Jan-18 6:10am    
You should read carefully what OG has written/suggested to you.
When I read your question I suppose that generally deriving should be a good approach for you - that means : create a BaseForm (as suggested) and derive the other Forms from it ...
Yu-Long Fang 5-Jan-18 6:24am    
Hello, Ralf,

I have never used BaseForm too.
I will also study that then decide which is the better solution for my project. Thank you!

Eric

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