Search code examples
c#winformsvisual-web-gui

Dealing with control flexibility


I've a question more about 'Good Programming Practices'. I have just started a really big project. I'm using WebGui (long story short.. it is WinForms in web) - but it's not important.

I'm creating milions of forms with milions of controls like TextBox, NumericUpDown, DateTimePicker and etc. It might happen, that I will have to change something in behavior of DateTimePicker or appearance. It will be impossible to change it in every control. I want my project to be flexible so I've got an idea..

I do separate custom controls for every type - string, numeric, date, byte.. and within I will put TextBox for example. And on every form I will put not TextBox, but MyTextBox. In fact, that MyTextBox will be just TextBox, but when I change something there, every control will be changed.

Is it good, popular pracitce in programming?


Solution

  • in the case of WPF this can be achieved quite easily using Styles and Templates. in Winforms this is not possible, therefore I'd say your approach of deriving from the controls and using your own custom controls on the UI is a good practical approach which helps managing changes centrally.

    If the controls were created manually in the programme, alternatively you could use a Factory clase(s) and get the Factories to create the controller object rather than just newing up. But this might not be possible when the UI is created by dragging and dropping controls as the developer has no control over the creation of controls.

    Which ever the approach you choose, the fundamental goal should be to centralize the creation logic of the controlls.