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. Code changes when switching from design to code view

Code changes when switching from design to code view

Scheduled Pinned Locked Moved C#
csharpcomdesignhelpquestion
6 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.
  • V Offline
    V Offline
    Vikram A Punathambekar
    wrote on last edited by
    #1

    I've been playing around with SharpDevelop and C#, and started doing very simple C# programs. I created a textbox using the design view, went to the code view and modified some code. I built and ran the program, and it worked. :) So far so good. But I switched to design view and back to code view again. Poof! My changes are gone. :| Bummer! My guess is that every time you switch from design to code view, it updates the code, throwing out changes you might have made. The change I made is in the InitializeComponent() method, if it helps. Does anybody know of a setting where I can disable this from happening? Or does it require a code fix? Cheers, Vikram.


    http://www.geocities.com/vpunathambekar "You still have the coolest name on CodeProject." — David Wulff to me.

    J P 2 Replies Last reply
    0
    • V Vikram A Punathambekar

      I've been playing around with SharpDevelop and C#, and started doing very simple C# programs. I created a textbox using the design view, went to the code view and modified some code. I built and ran the program, and it worked. :) So far so good. But I switched to design view and back to code view again. Poof! My changes are gone. :| Bummer! My guess is that every time you switch from design to code view, it updates the code, throwing out changes you might have made. The change I made is in the InitializeComponent() method, if it helps. Does anybody know of a setting where I can disable this from happening? Or does it require a code fix? Cheers, Vikram.


      http://www.geocities.com/vpunathambekar "You still have the coolest name on CodeProject." — David Wulff to me.

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      You shouldn't be able to edit this... that method is SPECIFICALLY for designer-generated code. If you need to change a setting in this method then you should be doing so using the designer/property grid.

      V 1 Reply Last reply
      0
      • V Vikram A Punathambekar

        I've been playing around with SharpDevelop and C#, and started doing very simple C# programs. I created a textbox using the design view, went to the code view and modified some code. I built and ran the program, and it worked. :) So far so good. But I switched to design view and back to code view again. Poof! My changes are gone. :| Bummer! My guess is that every time you switch from design to code view, it updates the code, throwing out changes you might have made. The change I made is in the InitializeComponent() method, if it helps. Does anybody know of a setting where I can disable this from happening? Or does it require a code fix? Cheers, Vikram.


        http://www.geocities.com/vpunathambekar "You still have the coolest name on CodeProject." — David Wulff to me.

        P Offline
        P Offline
        Patric_J
        wrote on last edited by
        #3

        When you use Visual Studio it adds the following little comment to your code right above the InitializeComponent() method #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() Put you changes in the OnLoad eventhandler or the contructor instead. /Patric My C# blog: C# Coach

        V D 2 Replies Last reply
        0
        • P Patric_J

          When you use Visual Studio it adds the following little comment to your code right above the InitializeComponent() method #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() Put you changes in the OnLoad eventhandler or the contructor instead. /Patric My C# blog: C# Coach

          V Offline
          V Offline
          Vikram A Punathambekar
          wrote on last edited by
          #4

          I saw those comments, but just did not know where else to put them. Besides, the changes I made were pretty 'harmless'. Patric_J wrote: Put you changes in the onload eventhandler or the contructor instead. That worked. I put them in the ctor *after* the call to InitializeComponent, and it worked beautifully. Thanks, Patric! Cheers, Vikram.


          http://www.geocities.com/vpunathambekar "You still have the coolest name on CodeProject." — David Wulff to me.

          1 Reply Last reply
          0
          • J J4amieC

            You shouldn't be able to edit this... that method is SPECIFICALLY for designer-generated code. If you need to change a setting in this method then you should be doing so using the designer/property grid.

            V Offline
            V Offline
            Vikram A Punathambekar
            wrote on last edited by
            #5

            I fixed it by putting the code in the form's ctor after the call to InitializeComponent(), as Patric suggested. Thanks! Cheers, Vikram.


            http://www.geocities.com/vpunathambekar "You still have the coolest name on CodeProject." — David Wulff to me.

            1 Reply Last reply
            0
            • P Patric_J

              When you use Visual Studio it adds the following little comment to your code right above the InitializeComponent() method #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() Put you changes in the OnLoad eventhandler or the contructor instead. /Patric My C# blog: C# Coach

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              Patric_J wrote: /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// Perhaps the comment should be modified to explicitly state that it's autogenerated code and that changes will be lost using the header generated by the xsd tool as a template. //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version: 1.1.4322.2032 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ // // This source code was auto-generated by xsd, Version=1.1.4322.2032. //

              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