views:

65

answers:

2

I am developing a GUI application in C# using the design mode in VS2008. Now that I am finished with the looks of the application I am ready to add some functionality to it.

What really confuses me though, is that VS2008 designer only uses the empty constructor. When developing applications in Java I normally pass around a model and controller object to every view object in the constructor.

I am unsure if I have used the designer too much and needs to hardcode more or if there is some other way to do it. How do you pass around data to view objects?

Hope you understand me

A: 

Hello,

Try to use : http://smartclient.codeplex.com/ (formerly known as Composite Application Block).

It's a MVP framework for Windows Form which allows you to do dependency injection of your presenter in your view.

Manitra.

Manitra Andriamitondra
Not really looking for thirdparty components. I am just a beginner in C# and winforms and dont quite understand how to use it.
bobjink
+1  A: 
  • you can use your constructor in subclasses of Form class without problems. However for Controls to be compatible with designer this doesn't work well.

  • You can pass model object to public property or method of you view object (form or control).

  • You can use Passive View or Supervising Controller patterns in which View knows little about model and is modified by Presenter.

elder_george
Thanks! I dont really like the third option. I want to keep it as MVC. But out of the first two, what is used more often by C# developers?To me it seems like a big limitation of winforms or have I just been using MVC wrongly in Java?
bobjink
Unfortunately code generator of WinForms designer is not smart enough to work with arguments in user controls. You can circumvent it by changing generated file (usually XXX.designer.cs) and replacing default constructor with constructor you need, but your changes will be most certainly lost. Or you can write form creation code by hand, but this can be very tedious and error-prone. So, the second way I've proposed earlier will be the easiest, IMHO.
elder_george