Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. User Control

User Control

Scheduled Pinned Locked Moved C#
csharpquestionvisual-studiohelpannouncement
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ismael_1999
    wrote on last edited by
    #1

    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.

    OriginalGriffO B R 3 Replies Last reply
    0
    • I Ismael_1999

      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.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "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

      I 1 Reply Last reply
      0
      • I Ismael_1999

        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.

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

        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

        I 1 Reply Last reply
        0
        • I Ismael_1999

          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.

          R Offline
          R Offline
          Ralf Meier
          wrote on last edited by
          #4

          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 ...

          B I 2 Replies Last reply
          0
          • R Ralf Meier

            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 ...

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • B BillWoodruff

              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

              I Offline
              I Offline
              Ismael_1999
              wrote on last edited by
              #6

              "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.

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                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!

                I Offline
                I Offline
                Ismael_1999
                wrote on last edited by
                #7

                Make the properties obsolete? I'll read more about. Thanks.

                OriginalGriffO 1 Reply Last reply
                0
                • R Ralf Meier

                  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 ...

                  I Offline
                  I Offline
                  Ismael_1999
                  wrote on last edited by
                  #8

                  Maybe you're right. I'll take a look. Thanks.

                  R 1 Reply Last reply
                  0
                  • I Ismael_1999

                    Make the properties obsolete? I'll read more about. Thanks.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    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!

                    "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

                    1 Reply Last reply
                    0
                    • I Ismael_1999

                      Maybe you're right. I'll take a look. Thanks.

                      R Offline
                      R Offline
                      Ralf Meier
                      wrote on last edited by
                      #10

                      you will see it ... ;-) And you are welcome ...

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups