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