Modifying user controls while modifying main form

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 1795 Views - Last Post: 12 July 2014 - 07:34 AM Rate Topic: -----

#1 danbywinby   User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 305
  • Joined: 06-January 13

Modifying user controls while modifying main form

Posted 10 July 2014 - 12:45 PM

Hi Guys

I am trying to modify a user control while modifying the main form. For example i have my main form open in one visual c# window and my user controls in another. However it seems that in order for my code changes in my user control to have any effect on the main form i need to close all my c# windows and then re-open them and even then that sometimes doesn't work am i doing anything wrong or is this supposed to happen??

Also yes i am saving and clicking build solution on my user controls.

Thank You

Is This A Good Question/Topic? 0
  • +

Replies To: Modifying user controls while modifying main form

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 23,986
  • Joined: 05-May 12

Re: Modifying user controls while modifying main form

Posted 10 July 2014 - 12:59 PM

View Postdanbywinby, on 10 July 2014 - 03:45 PM, said:

am i doing anything wrong

<sarcasm>Yes. You are still using WinForms instead of WPF.</sarcasm>

In all seriousness, though, the Visual Studio WinForms Designer isn't exactly the best design environment for the sophisticated user. It's great for beginners, but when you start doing something like have a user control being edited and at the same time have that user control be inside a form that is also being edited at the same time, things don't work too well. Heck, you can't even use proper object oriented inheritance with forms with the Designer. (eg. DepositForm and Withdrawal Form derive from TransactionForm.)

Stop and think about it, unlike the WPF editor where a "ghost" assembly is built on the fly and refreshed as it completes, the WinForms editor depends on you to recompile the assembly that has the user control, and then for the user to force some kind of operation that would reload the assembly back into the Designer. It gets even worse when the user control and form live within the same assembly. Sometimes the Designer just crashes and you can't reload anything without starting from scratch. This used to be quite a common problem back with VS2005 and VS2008 such that I finally gave up and just edit my GUI components by hand, much to the dismay of my co-workers who are dependent on the Designer. VS2010 and later supposedly got better, but I've been burned enough that I don't try anymore. I moved on to WPF.
Was This Post Helpful? 1
  • +
  • -

#3 danbywinby   User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 305
  • Joined: 06-January 13

Re: Modifying user controls while modifying main form

Posted 10 July 2014 - 01:06 PM

Well i still am a beginner and what i am working on now or trying to is/will be my first big c# project. I've never ever used WPF only WinForms because one that is what i was taught in college a few years ago and two because my other mates on my apprenticeship use WinForms. Plus i did load up the WPF start screen a while back and took one look and though no way so i went back to WinForms.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Modifying user controls while modifying main form

Posted 10 July 2014 - 04:01 PM

He's right.

If you only own a hammer you try to see every problem as a nail.

The simple fact is WinForms is really not the right tool for this job. WPF is much more conducive to dynamic changes in presentation at run time. (as well as being more conducive to employment after the year 1990)
Was This Post Helpful? 0
  • +
  • -

#5 danbywinby   User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 305
  • Joined: 06-January 13

Re: Modifying user controls while modifying main form

Posted 10 July 2014 - 11:03 PM

Ok but is WPF a lot different to WinForms or not much different and so will be quick for me to learn or am I basically gonna have to start from scratch to learn WPF?
Was This Post Helpful? 0
  • +
  • -

#6 Michael26   User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 02:18 AM

The key point in Windows presentation foundation is presentation, something the WinForms didn't pay attention to. It presents the information from a datamodel you created, this was a thing in the past, people used WinForms Controls as placeholders for data tightly binding it together so any change would cascade up, so instead of just changing one thing you end up changing 2 or 3 more just to keep the model working.
Does this make sense to you?
Was This Post Helpful? 0
  • +
  • -

#7 danbywinby   User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 305
  • Joined: 06-January 13

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 04:49 AM

Sorry but no now you've confused me even more
Was This Post Helpful? 0
  • +
  • -

#8 Charles:)   User is offline

  • D.I.C Regular

Reputation: 149
  • View blog
  • Posts: 359
  • Joined: 26-November 09

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 05:19 AM

View Postdanbywinby, on 11 July 2014 - 07:03 AM, said:

Ok but is WPF a lot different to WinForms or not much different and so will be quick for me to learn or am I basically gonna have to start from scratch to learn WPF?


You can port some of your WinForms knowledge over to WPF, but I think there's quite a lot that you'll need to learn from scratch for WPF. It's worth it though, trust me.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 05:21 AM

Please clarify (it isn't clear to me): Are you building user (custom) controls that other people will be able to use and add to their applications? Or are you building an application that happens to include user-controls?

If the latter, and you are still making changes to the user-control(s), then you will have to continue to re-build (and re-construct) the solution/projects as you progress.

If the former then this seems a little challenging to me, for a first project for a beginner.
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 05:25 AM

View Postdanbywinby, on 11 July 2014 - 12:03 AM, said:

Ok but is WPF a lot different to WinForms or not much different and so will be quick for me to learn or am I basically gonna have to start from scratch to learn WPF?


That truly depends on how good your WinForms usage really is. If you did proper development where you strongly seperated your logic code from your GUI code, then you're probably in really good shape. If you did a lot of poor design where your logic was tightly dependent on your GUI then you have a lot of bad habits to break whether you stay in WinForms or shift to WPF.

WinForms did not make it a priority for developers to separate the presentation interface (the GUI or the Form) from the logic that did the work. So a large percentage of developers did a lot of fast and dirty development.

WPF is still C# doing all the work. What you have to change is just how you build the UI and how you interact with it. Basically what you have to learn is to UNLEARN all the bad habits that most WinForms developers (including myself) built up.
Was This Post Helpful? 0
  • +
  • -

#11 danbywinby   User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 305
  • Joined: 06-January 13

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 05:28 AM

View Postandrewsw, on 11 July 2014 - 05:21 AM, said:

Please clarify (it isn't clear to me): Are you building user (custom) controls that other people will be able to use and add to their applications? Or are you building an application that happens to include user-controls?

If the latter, and you are still making changes to the user-control(s), then you will have to continue to re-build (and re-construct) the solution/projects as you progress.

If the former then this seems a little challenging to me, for a first project for a beginner.


Basically I am trying to build an application that will sort of like a wizard with many different screens and after searching on the web I saw that one of the solutions was to have one main form with several different screens but each screen would be a seep rate user control e.g. First screen on launch would be the login screen (user control 1) and then after successful login the home screen would be displayed (user control 2).

View PosttlhIn`toq, on 11 July 2014 - 05:25 AM, said:

View Postdanbywinby, on 11 July 2014 - 12:03 AM, said:

Ok but is WPF a lot different to WinForms or not much different and so will be quick for me to learn or am I basically gonna have to start from scratch to learn WPF?


That truly depends on how good your WinForms usage really is. If you did proper development where you strongly seperated your logic code from your GUI code, then you're probably in really good shape. If you did a lot of poor design where your logic was tightly dependent on your GUI then you have a lot of bad habits to break whether you stay in WinForms or shift to WPF.

WinForms did not make it a priority for developers to separate the presentation interface (the GUI or the Form) from the logic that did the work. So a large percentage of developers did a lot of fast and dirty development.

WPF is still C# doing all the work. What you have to change is just how you build the UI and how you interact with it. Basically what you have to learn is to UNLEARN all the bad habits that most WinForms developers (including myself) built up.


Well in that case then I am in really bad shape because as I said before this is my first big c# project apart from a few small projects which I did at college several years ago.
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 05:51 AM

I think you're starting to see your current situation. Even you are saying that your current skillset comes from "several years ago". Its your choice if you want to stay in the past or move forward to the present.

I don't just mean the choice between WinForms and WPF. I'm talking about good and bad habits as well as good and bad design.

Every program you make using your old poor design methodology ingrains those bad habits that much more. Making it even harder to break out of those habits.

I don't care if you stay in WinForms or move to WPF right now. But please, work on breaking the bad habits of designing where your logic is dependent on the GUI. Your logic code should be able to move from a console application, to a WinForms app to a WPF application with minimal modification. In WinForms we called it a MVC design (Model View Controller). In WPF we try to stick to an MVVM pattern (Model, View, ViewModel). Either way you have the same basic plan:
You have a model which is your data, completely unaware of the UI.
You have a view, which is your UI, completely unaware of the data model.
You have a controller of some type which is the layer between View and the Model.

So you could make your logic which doesn't care how the properties get set, whether its from console input, WinForms input, an internet connection, whatever. That does 90% of the real work. Then you have a layer that interprets between the work and the display. Then you have the display that gets its info from the in-between layer.

Like I said, you can do all this in WinForms. Or you can do all this in WPF. But since it is all new technology and design to you anyway, it just makes more sense to spend 5,000 hours of learning on the new WPF that is more powerful, more flexible and more in demand by employers - than it does to spend the same number of hours on older tech that people are moving away from for good reason.
Was This Post Helpful? 2
  • +
  • -

#13 Michael26   User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 05:54 AM

For a big project the most important thing is to plan your project, don't just start writing code right away. What you use, WinForms or WPF is not really important in this stage. All you said is you have a big project but didn't specify at what stage of the project is, if you started writing code i assume you already have at least some plan what project should do. Are you familiar with Object oriented programming or Universal modeling language?

If this seems to much, maybe you should brush up on your C# skills before you dive deep into your project.
Was This Post Helpful? 1
  • +
  • -

#14 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 06:05 AM

OP said:

Basically I am trying to build an application that will sort of like a wizard with many different screens and after searching on the web I saw that one of the solutions was to have one main form with several different screens but each screen would be a seep rate user control e.g. First screen on launch would be the login screen (user control 1) and then after successful login the home screen would be displayed (user control 2).

As you are struggling to achieve this using user-controls then a simpler approach is to use several forms, hiding or closing the previous form, and making sure that each form is at the same position and size as the previous one. (The first/main form would need to remain open but hidden, otherwise the application will exit.)

It is also possible to hide and show sets of controls on the same form. However, this quickly becomes messy if there are several wizard-steps and many controls.

This post has been edited by andrewsw: 11 July 2014 - 06:07 AM

Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Modifying user controls while modifying main form

Posted 11 July 2014 - 06:18 AM

Personally I *hate* the multiple form approach. Its so 1980's and ugly. Maybe ok for one monitor, but post times it becomes a mess on multiple monitors, presumes you want everything to open on the primary screen which the user may not want. Form up, form down, form up, form down, form up, form down... Gawd no.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2