User Control
-
Hi, folks. I created a user control with some properties and methods and used it in a Forms project where it appears many times. It's working fine. But now I decided to improve some characteristics and I eliminated some properties and added some. The problem is that the forms where this control appears show errors and it' very difficult to open the form. After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted. What is the best way to substitute a control under these circumstances? I use C# in Visual Studio 2019. Thanks.
-
Hi, folks. I created a user control with some properties and methods and used it in a Forms project where it appears many times. It's working fine. But now I decided to improve some characteristics and I eliminated some properties and added some. The problem is that the forms where this control appears show errors and it' very difficult to open the form. After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted. What is the best way to substitute a control under these circumstances? I use C# in Visual Studio 2019. Thanks.
The problem is probably that as you say:
Quote:
I eliminated some properties and added some.
If any of the classes that use your control are referencing those properties, the new version will just not work: the properties no longer exist. The proper way to do that is to depreciate the properties, not remove them: that way they can still be used but there is a warning that they shouldn't be used in new projects. That is documentation only, however - for later versions, you can make them actually obsolete: ObsoleteAttribute Class (System) | Microsoft Docs[^] but you should allow a good time for people to migrate to the newer version before that happens. Often, a more developer friendly way to do this with drastic changes is to end support for the existing version, and develop a new version for future projects.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Hi, folks. I created a user control with some properties and methods and used it in a Forms project where it appears many times. It's working fine. But now I decided to improve some characteristics and I eliminated some properties and added some. The problem is that the forms where this control appears show errors and it' very difficult to open the form. After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted. What is the best way to substitute a control under these circumstances? I use C# in Visual Studio 2019. Thanks.
Member 14792393 wrote:
I decided to improve some characteristics and I eliminated some properties and added some.
A key question is what you did to the Forms that had instances of the UserControl that used the removed Properties: of course any attempted use/access of/to removed "anything" results in compile errors.
Member 14792393 wrote:
After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted
This just doesn't make sense: did you edit the form code to remove any code that used the UserControl instance, and, then, re-build the Project/Solution? Did you re-build the solution after adding the new version of the UserControl? There is (imho) a defect in Visual Studio that has never been fixed: you can modify a UserControl ... for example, add some new Control to it ... and, the change doesn't appear in currently open design-time Form Windows even after you re-build the solution. However, if you close the designer window, and re-open it: the view has been updated.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
-
Hi, folks. I created a user control with some properties and methods and used it in a Forms project where it appears many times. It's working fine. But now I decided to improve some characteristics and I eliminated some properties and added some. The problem is that the forms where this control appears show errors and it' very difficult to open the form. After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted. What is the best way to substitute a control under these circumstances? I use C# in Visual Studio 2019. Thanks.
If you really have removed Properties you have to realize that those Properties perhaps are used by the Designer-Script of your Form. So you must open the DesignerScript of your Form, find those part which assignes the Properties of this Control and delete those Assignments which are not more existent ...
-
If you really have removed Properties you have to realize that those Properties perhaps are used by the Designer-Script of your Form. So you must open the DesignerScript of your Form, find those part which assignes the Properties of this Control and delete those Assignments which are not more existent ...
good point from a slightly different angle :)
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
-
Member 14792393 wrote:
I decided to improve some characteristics and I eliminated some properties and added some.
A key question is what you did to the Forms that had instances of the UserControl that used the removed Properties: of course any attempted use/access of/to removed "anything" results in compile errors.
Member 14792393 wrote:
After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted
This just doesn't make sense: did you edit the form code to remove any code that used the UserControl instance, and, then, re-build the Project/Solution? Did you re-build the solution after adding the new version of the UserControl? There is (imho) a defect in Visual Studio that has never been fixed: you can modify a UserControl ... for example, add some new Control to it ... and, the change doesn't appear in currently open design-time Form Windows even after you re-build the solution. However, if you close the designer window, and re-open it: the view has been updated.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
"did you edit the form code to remove any code that used the UserControl instance, and, then, re-build the Project/Solution? Did you re-build the solution after adding the new version of the UserControl?" Yes, but the application is too big and has many instances of the control. What I intend to do now is to rename the new version of the control and add it to the project. Then I open each form, erase the old version and insert the new version. After that I can remove the old version. It's a hard job, but I think it's the only way. What do you think? Thanks.
-
The problem is probably that as you say:
Quote:
I eliminated some properties and added some.
If any of the classes that use your control are referencing those properties, the new version will just not work: the properties no longer exist. The proper way to do that is to depreciate the properties, not remove them: that way they can still be used but there is a warning that they shouldn't be used in new projects. That is documentation only, however - for later versions, you can make them actually obsolete: ObsoleteAttribute Class (System) | Microsoft Docs[^] but you should allow a good time for people to migrate to the newer version before that happens. Often, a more developer friendly way to do this with drastic changes is to end support for the existing version, and develop a new version for future projects.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
Make the properties obsolete? I'll read more about. Thanks.
-
If you really have removed Properties you have to realize that those Properties perhaps are used by the Designer-Script of your Form. So you must open the DesignerScript of your Form, find those part which assignes the Properties of this Control and delete those Assignments which are not more existent ...
Maybe you're right. I'll take a look. Thanks.
-
Make the properties obsolete? I'll read more about. Thanks.
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Maybe you're right. I'll take a look. Thanks.
you will see it ... ;-) And you are welcome ...