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. Windows Forms
  4. Is it possible to modify InitializeComponent() safely?

Is it possible to modify InitializeComponent() safely?

Scheduled Pinned Locked Moved Windows Forms
winformsdesignquestion
7 Posts 2 Posters 2 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.
  • S Offline
    S Offline
    SlingBlade
    wrote on last edited by
    #1

    Until recently I have been keeping Data layer objects and task logic as seperate from the UI logic as possible. I have been experimenting with custom user controls and attempting to integrate the custom datalayers with the designer by modifying the InitializeComponent method. I have been successful in integrating my data layer data into the designer, however, it doesn't like to stay. Are there any easy workarounds to this such as a way to tell the designer not to modify a peace of code in the InitializeComponent method?

    C 1 Reply Last reply
    0
    • S SlingBlade

      Until recently I have been keeping Data layer objects and task logic as seperate from the UI logic as possible. I have been experimenting with custom user controls and attempting to integrate the custom datalayers with the designer by modifying the InitializeComponent method. I have been successful in integrating my data layer data into the designer, however, it doesn't like to stay. Are there any easy workarounds to this such as a way to tell the designer not to modify a peace of code in the InitializeComponent method?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      SlingBlade wrote:

      Are there any easy workarounds to this such as a way to tell the designer not to modify a peace of code in the InitializeComponent method?

      InitializeComponent is the designers method. You cannot change it because the designer will overwrite your changes. In VS2005 it has been moved out to a separate file which you should not be editing either.

      SlingBlade wrote:

      I have been successful in integrating my data layer data into the designer

      The data layer should be no where near the designer. What ever it is that you have done, it isn't separate the data layer from the presentation layer. The data layer and presentation layer should not meet at all. There should be a business layer in between.


      Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        SlingBlade wrote:

        Are there any easy workarounds to this such as a way to tell the designer not to modify a peace of code in the InitializeComponent method?

        InitializeComponent is the designers method. You cannot change it because the designer will overwrite your changes. In VS2005 it has been moved out to a separate file which you should not be editing either.

        SlingBlade wrote:

        I have been successful in integrating my data layer data into the designer

        The data layer should be no where near the designer. What ever it is that you have done, it isn't separate the data layer from the presentation layer. The data layer and presentation layer should not meet at all. There should be a business layer in between.


        Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

        S Offline
        S Offline
        SlingBlade
        wrote on last edited by
        #3

        I'm going to agree to disagree here. I'm pretty sure it is a lost cause trying to get support for something that is clearly defined as unsupported. Data, business and presentation is how I have always done it, but like I mentioned I am getting into developing custom controls that make the presentation layer much simpler and well defined to what need be accomplished, that and Microsoft offers the ability to define your entire data layer within the presentation layer. The data layer is still seperated with a business layer. I am really looking for a way to bring the schema into the designer so my custom controls can be assigned to the proper datatables that are returned in a data layer method without manually creating the schema for every table within the local Dataset for the control.

        C 1 Reply Last reply
        0
        • S SlingBlade

          I'm going to agree to disagree here. I'm pretty sure it is a lost cause trying to get support for something that is clearly defined as unsupported. Data, business and presentation is how I have always done it, but like I mentioned I am getting into developing custom controls that make the presentation layer much simpler and well defined to what need be accomplished, that and Microsoft offers the ability to define your entire data layer within the presentation layer. The data layer is still seperated with a business layer. I am really looking for a way to bring the schema into the designer so my custom controls can be assigned to the proper datatables that are returned in a data layer method without manually creating the schema for every table within the local Dataset for the control.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          SlingBlade wrote:

          I'm going to agree to disagree here. I'm pretty sure it is a lost cause trying to get support for something that is clearly defined as unsupported.

          I'm not entirely sure what you are disagreeing with. I'm suggesting that you cannot change the code in the InitializeComponent method because it is unsupported as Visual Studio will overwrite any changes you make. Then you say you disagree with me because it is a "lost cause trying to get support for something that is clearly defined as unsupported".

          SlingBlade wrote:

          that and Microsoft offers the ability to define your entire data layer within the presentation layer.

          Just because you can do something, doesn't mean you should do something. I can walk up a set of railway tracks. However, doing so is clearly inadvised.


          Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          S 1 Reply Last reply
          0
          • C Colin Angus Mackay

            SlingBlade wrote:

            I'm going to agree to disagree here. I'm pretty sure it is a lost cause trying to get support for something that is clearly defined as unsupported.

            I'm not entirely sure what you are disagreeing with. I'm suggesting that you cannot change the code in the InitializeComponent method because it is unsupported as Visual Studio will overwrite any changes you make. Then you say you disagree with me because it is a "lost cause trying to get support for something that is clearly defined as unsupported".

            SlingBlade wrote:

            that and Microsoft offers the ability to define your entire data layer within the presentation layer.

            Just because you can do something, doesn't mean you should do something. I can walk up a set of railway tracks. However, doing so is clearly inadvised.


            Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            S Offline
            S Offline
            SlingBlade
            wrote on last edited by
            #5

            I was refering to Microsoft not providing a way to manually interact with the designer. People come up with new design patterns all the time and I particularly considered what I was trying to accomplish as an innovative compromise to keeping the data layer seperate from the presentation layer but still be able to define how the presentation layer interacts with the data layer more clearly. Sorry for the run on sentence. What I'm trying to get at here is that I am using VS Express and am not currently at liberty to make feature requests directly. Sure modifying InitializeComponent is a bit dangerous, but, it's my machine I'm crashing and it sounds like Microsoft is just being lazy with it's almost limitless supply of resources to not provide a workaround. Since when has Microsoft been about following all standards exactly?

            C 1 Reply Last reply
            0
            • S SlingBlade

              I was refering to Microsoft not providing a way to manually interact with the designer. People come up with new design patterns all the time and I particularly considered what I was trying to accomplish as an innovative compromise to keeping the data layer seperate from the presentation layer but still be able to define how the presentation layer interacts with the data layer more clearly. Sorry for the run on sentence. What I'm trying to get at here is that I am using VS Express and am not currently at liberty to make feature requests directly. Sure modifying InitializeComponent is a bit dangerous, but, it's my machine I'm crashing and it sounds like Microsoft is just being lazy with it's almost limitless supply of resources to not provide a workaround. Since when has Microsoft been about following all standards exactly?

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              SlingBlade wrote:

              Sure modifying InitializeComponent is a bit dangerous, but, it's my machine I'm crashing and it sounds like Microsoft is just being lazy with it's almost limitless supply of resources to not provide a workaround.

              It occurs to me that since InitialiseComponent is called from the constructor, why not create your own method and call it from the constructor too?


              Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

              S 1 Reply Last reply
              0
              • C Colin Angus Mackay

                SlingBlade wrote:

                Sure modifying InitializeComponent is a bit dangerous, but, it's my machine I'm crashing and it sounds like Microsoft is just being lazy with it's almost limitless supply of resources to not provide a workaround.

                It occurs to me that since InitialiseComponent is called from the constructor, why not create your own method and call it from the constructor too?


                Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                S Offline
                S Offline
                SlingBlade
                wrote on last edited by
                #7

                That works fine at run time, but does not show up in the designer, even if you do the work before the InitializeComponent call in the constructor. I am thinking I am just going to have to manually define the table schemas in the dataset and have them filled at run time for the clarity I am going for. It is a bit more work and debugging but those are the breaks I guess. Thanks for helping keep me from going too far off on a tangent. It's kind of weird to mention this but even my horoscope that just hit my hotmail is in agreement with you. "Impose a looser, more go-with-the-flow kind of structure on your work habits, and you just might accomplish even more than you hoped. The payoffs may not be immediate, but they'll greatly benefit your future."

                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