General problem with c sharp in VS2005
-
I'm very new to C sharp, having come from a c++ and vb background. Within VS2005, I have a script (MainForm.Designer.cs) that defines all the components in my project (mostly toolstripmenus, buttons, labels, comboboxes etc.), the events attached to them etc However, every time I try to group the code into logical blocks (including using regions) and save it, when I re-open VS mixes it all up again. I've gone through the help and even tried MSDN, but haven't found a way around this. Anyone got any ideas? Thanks in Advance, John.
-
I'm very new to C sharp, having come from a c++ and vb background. Within VS2005, I have a script (MainForm.Designer.cs) that defines all the components in my project (mostly toolstripmenus, buttons, labels, comboboxes etc.), the events attached to them etc However, every time I try to group the code into logical blocks (including using regions) and save it, when I re-open VS mixes it all up again. I've gone through the help and even tried MSDN, but haven't found a way around this. Anyone got any ideas? Thanks in Advance, John.
Hi, all .Designer.cs files are generated automatically by Visual Designer; you are not supposed to modify them in any way other than through the Designer. So you should put your own code in one or more separate files. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Happy Holidays!
-
Hi, all .Designer.cs files are generated automatically by Visual Designer; you are not supposed to modify them in any way other than through the Designer. So you should put your own code in one or more separate files. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Happy Holidays!
-
Thanks Luc, Just so I understand correctly, are you suggesting that I put the code from the designer script into my own script and simply call the functions from the designer script? Best, John.
why would you do any of that? Leave the Designer code as is, where it is; the .Designer.cs files are part of your project, they will be included in all your builds. And there is nothing to call except for InitializeComponent(), which should be called as the first statement in your form's constructor (the wizzard will have put it there for you too). :)
Luc Pattyn [Forum Guidelines] [My Articles]
Happy Holidays!
-
Thanks Luc, Just so I understand correctly, are you suggesting that I put the code from the designer script into my own script and simply call the functions from the designer script? Best, John.
You'll notice that your MainForm.cs and MainForm.Designer.cs both have: public partial class MainForm within the same namespace. The designer file is handled by the IDE and automatically updated everytime design changes are made (this can include project opening etc). You shouldn't normally make any changes to the designer file yourself. Your own 'functions' and calls to them should be added in the MainForm.cs file, or alternatively create your own MainForm.Functions.cs and/or MainForm.FunctionCalls.cs file and start these files with the namespace required and the public partial class MainForm { .... }
-
Thanks Luc, Just so I understand correctly, are you suggesting that I put the code from the designer script into my own script and simply call the functions from the designer script? Best, John.
jgrogan wrote:
are you suggesting that I put the code from the designer script into my own script and simply call the functions from the designer script?
No, leave them as they are.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon