|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Studio 2005 and the ".Designer" file...?!? Code practice in properties.I have a created a custom usercontrol which inherites an Excel like usercontrol. In this usercontrol I have a custom property called SpreadTemplate, which is an enum with (at the moment) two members called None and Pipeline. When I set this property at design time it sets up the activesheet with a number of columns, rows, headers etc. This is all fine and working as it is supposed to. The problem is that all this information gets written to the [form].designer file, which makes it more or less permanent. Meaning if I change the way SpreadTemplate sets up the form, I will have to go back into design time and reset the property, before it has any effect. The code in the [form].designer file looks like this (in VB.Net, but the same happens using C#): ' 'CalsepSpecificSpread1 ' Me.CalsepSpecificSpread1.About = "2.5.2007.2005" .... Me.SpreadTemplate = Pipeline ' 'CalsepSpecificSpread1_Sheet1 ' Me.CalsepSpecificSpread1_Sheet1.SheetName = "Pipeline" Me.CalsepSpecificSpread1_Sheet1.ColumnCount = 7 Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.RowCount = 2 Me.CalsepSpecificSpread1_Sheet1.RowCount = 1 Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.AutoText = FarPoint.Win.Spread.HeaderAutoText.Blank Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Border = ComplexBorder1 Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Value = "x-Position" Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Border = ComplexBorder1 Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Value = "y-Position" .... Me.CalsepSpecificSpread1_Sheet1.Columns.Get(0).Width = 89.0! .... And here comes another problem (besides having to go to the designer and reapply the setting) and that is that some of the properties are different at runtime (based on other settings), but these are overridden by the ones above. Meaning when the line Me.SpreadTemplate = Pipeline is done at runtime it might generate another text for columnheader (0, 0), but this is then changed back into "x-position" by the code generated in the [form].designer file. I have tried experimenting with setting <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _ on the SpreadTemplate property, but this only affects whether the line Me.SpreadTemplate = Pipeline gets written to the .designer file. I realize that this is properly standard Visual Studio 2005, but still it strikes me as pretty weird behaviour. Is there any way to deactivate this or do anyone have another idea as how to handle this kind of thing? Is it not good code practice to have one property set a number of other properties? I could of course just do the SpreadTemplate = Pipeline on form load or some other place that only gets called during runtime, but I want to be able to see the changes at design time, so I can design the rest of the form. I am really baffled at this behaviour, please advise...! Regards ....Seth Seth,
If you don't want a public member to be serialized in the InitializeComponent method you can attribute the member with [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] -- Show quoteHide quoteHTH Stoitcho Goutsev (100) "Seth Gecko" <sege***@gmail.com> wrote in message news:1169831913.919882.272330@m58g2000cwm.googlegroups.com... > Hi > > I have a created a custom usercontrol which inherites an Excel like > usercontrol. In this usercontrol I have a custom property called > SpreadTemplate, which is an enum with (at the moment) two members > called None and Pipeline. > > When I set this property at design time it sets up the activesheet with > a number of columns, rows, headers etc. This is all fine and working as > it is supposed to. The problem is that all this information gets > written to the [form].designer file, which makes it more or less > permanent. Meaning if I change the way SpreadTemplate sets up the form, > I will have to go back into design time and reset the property, before > it has any effect. The code in the [form].designer file looks like this > (in VB.Net, but the same happens using C#): > > ' > 'CalsepSpecificSpread1 > ' > > Me.CalsepSpecificSpread1.About = "2.5.2007.2005" > ... > Me.SpreadTemplate = Pipeline > > ' > 'CalsepSpecificSpread1_Sheet1 > ' > Me.CalsepSpecificSpread1_Sheet1.SheetName = "Pipeline" > Me.CalsepSpecificSpread1_Sheet1.ColumnCount = 7 > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.RowCount = 2 > Me.CalsepSpecificSpread1_Sheet1.RowCount = 1 > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.AutoText = > FarPoint.Win.Spread.HeaderAutoText.Blank > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Border = > ComplexBorder1 > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Value = > "x-Position" > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Border = > ComplexBorder1 > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Value = > "y-Position" > ... > Me.CalsepSpecificSpread1_Sheet1.Columns.Get(0).Width = 89.0! > ... > > And here comes another problem (besides having to go to the designer > and reapply the setting) and that is that some of the properties are > different at runtime (based on other settings), but these are > overridden by the ones above. Meaning when the line Me.SpreadTemplate = > Pipeline is done at runtime it might generate another text for > columnheader (0, 0), but this is then changed back into "x-position" by > the code generated in the [form].designer file. I have tried > experimenting with setting > <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> > _ > on the SpreadTemplate property, but this only affects whether the line > Me.SpreadTemplate = Pipeline gets written to the .designer file. > > I realize that this is properly standard Visual Studio 2005, but still > it strikes me as pretty weird behaviour. Is there any way to deactivate > this or do anyone have another idea as how to handle this kind of > thing? Is it not good code practice to have one property set a number > of other properties? I could of course just do the SpreadTemplate = > Pipeline on form load or some other place that only gets called during > runtime, but I want to be able to see the changes at design time, so I > can design the rest of the form. I am really baffled at this behaviour, > please advise...! > > Regards > ...Seth > Yeah, that was also what I tried, ie. I added the attribute to my
SpreadTemplate property, but the only effect was the Me.SpreadTemplate = Pipeline line wasn't written to the InitializeComponent method. All of the properties I set on the inherited control was still written. Is there any way to prevent this? You cannot set the attribute for the entire class (I tried) and I don't know how I can set it on methods and properties on the base control. Perhaps overriding them, but in this case that will be quite a lot of properties... Suggestions? ....Seth Show quoteHide quote On 26 Jan., 18:59, "Stoitcho Goutsev \(100\)" <1***@100.com> wrote: > Seth, > > If you don't want a public member to be serialized in the > InitializeComponent method you can attribute the member with > > [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] > > -- > HTH > Stoitcho Goutsev (100) > > "Seth Gecko" <sege***@gmail.com> wrote in messagenews:1169831913.919882.272***@m58g2000cwm.googlegroups.com... > > > > > Hi > > > I have a created a custom usercontrol which inherites an Excel like > > usercontrol. In this usercontrol I have a custom property called > > SpreadTemplate, which is an enum with (at the moment) two members > > called None and Pipeline. > > > When I set this property at design time it sets up the activesheet with > > a number of columns, rows, headers etc. This is all fine and working as > > it is supposed to. The problem is that all this information gets > > written to the [form].designer file, which makes it more or less > > permanent. Meaning if I change the way SpreadTemplate sets up the form, > > I will have to go back into design time and reset the property, before > > it has any effect. The code in the [form].designer file looks like this > > (in VB.Net, but the same happens using C#): > > > ' > > 'CalsepSpecificSpread1 > > ' > > > Me.CalsepSpecificSpread1.About = "2.5.2007.2005" > > ... > > Me.SpreadTemplate = Pipeline > > > ' > > 'CalsepSpecificSpread1_Sheet1 > > ' > > Me.CalsepSpecificSpread1_Sheet1.SheetName = "Pipeline" > > Me.CalsepSpecificSpread1_Sheet1.ColumnCount = 7 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.RowCount = 2 > > Me.CalsepSpecificSpread1_Sheet1.RowCount = 1 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.AutoText = > > FarPoint.Win.Spread.HeaderAutoText.Blank > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Border = > > ComplexBorder1 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Value = > > "x-Position" > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Border = > > ComplexBorder1 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Value = > > "y-Position" > > ... > > Me.CalsepSpecificSpread1_Sheet1.Columns.Get(0).Width = 89.0! > > ... > > > And here comes another problem (besides having to go to the designer > > and reapply the setting) and that is that some of the properties are > > different at runtime (based on other settings), but these are > > overridden by the ones above. Meaning when the line Me.SpreadTemplate = > > Pipeline is done at runtime it might generate another text for > > columnheader (0, 0), but this is then changed back into "x-position" by > > the code generated in the [form].designer file. I have tried > > experimenting with setting > > <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> > > _ > > on the SpreadTemplate property, but this only affects whether the line > > Me.SpreadTemplate = Pipeline gets written to the .designer file. > > > I realize that this is properly standard Visual Studio 2005, but still > > it strikes me as pretty weird behaviour. Is there any way to deactivate > > this or do anyone have another idea as how to handle this kind of > > thing? Is it not good code practice to have one property set a number > > of other properties? I could of course just do the SpreadTemplate = > > Pipeline on form load or some other place that only gets called during > > runtime, but I want to be able to see the changes at design time, so I > > can design the rest of the form. I am really baffled at this behaviour, > > please advise...! > > > Regards > > ...Seth- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn - Seth,
You need to apply the attribute to all properties that you don't want to be serialized (you need to override or overload them). There are other ways to prevent a property to be serialized (ShouldSerializeXXX methods), but they also work on property-by-property basis. -- HTH Stoitcho Goutsev (100) "Seth Gecko" <sege***@gmail.com> wrote in message Yeah, that was also what I tried, ie. I added the attribute to mynews:1169901044.727733.38900@j27g2000cwj.googlegroups.com... SpreadTemplate property, but the only effect was the Me.SpreadTemplate = Pipeline line wasn't written to the InitializeComponent method. All of the properties I set on the inherited control was still written. Is there any way to prevent this? You cannot set the attribute for the entire class (I tried) and I don't know how I can set it on methods and properties on the base control. Perhaps overriding them, but in this case that will be quite a lot of properties... Suggestions? ....Seth Show quoteHide quote On 26 Jan., 18:59, "Stoitcho Goutsev \(100\)" <1***@100.com> wrote: > Seth, > > If you don't want a public member to be serialized in the > InitializeComponent method you can attribute the member with > > [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] > > -- > HTH > Stoitcho Goutsev (100) > > "Seth Gecko" <sege***@gmail.com> wrote in > messagenews:1169831913.919882.272***@m58g2000cwm.googlegroups.com... > > > > > Hi > > > I have a created a custom usercontrol which inherites an Excel like > > usercontrol. In this usercontrol I have a custom property called > > SpreadTemplate, which is an enum with (at the moment) two members > > called None and Pipeline. > > > When I set this property at design time it sets up the activesheet with > > a number of columns, rows, headers etc. This is all fine and working as > > it is supposed to. The problem is that all this information gets > > written to the [form].designer file, which makes it more or less > > permanent. Meaning if I change the way SpreadTemplate sets up the form, > > I will have to go back into design time and reset the property, before > > it has any effect. The code in the [form].designer file looks like this > > (in VB.Net, but the same happens using C#): > > > ' > > 'CalsepSpecificSpread1 > > ' > > > Me.CalsepSpecificSpread1.About = "2.5.2007.2005" > > ... > > Me.SpreadTemplate = Pipeline > > > ' > > 'CalsepSpecificSpread1_Sheet1 > > ' > > Me.CalsepSpecificSpread1_Sheet1.SheetName = "Pipeline" > > Me.CalsepSpecificSpread1_Sheet1.ColumnCount = 7 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.RowCount = 2 > > Me.CalsepSpecificSpread1_Sheet1.RowCount = 1 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.AutoText = > > FarPoint.Win.Spread.HeaderAutoText.Blank > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Border = > > ComplexBorder1 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 0).Value = > > "x-Position" > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Border = > > ComplexBorder1 > > Me.CalsepSpecificSpread1_Sheet1.ColumnHeader.Cells.Get(0, 1).Value = > > "y-Position" > > ... > > Me.CalsepSpecificSpread1_Sheet1.Columns.Get(0).Width = 89.0! > > ... > > > And here comes another problem (besides having to go to the designer > > and reapply the setting) and that is that some of the properties are > > different at runtime (based on other settings), but these are > > overridden by the ones above. Meaning when the line Me.SpreadTemplate = > > Pipeline is done at runtime it might generate another text for > > columnheader (0, 0), but this is then changed back into "x-position" by > > the code generated in the [form].designer file. I have tried > > experimenting with setting > > <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> > > _ > > on the SpreadTemplate property, but this only affects whether the line > > Me.SpreadTemplate = Pipeline gets written to the .designer file. > > > I realize that this is properly standard Visual Studio 2005, but still > > it strikes me as pretty weird behaviour. Is there any way to deactivate > > this or do anyone have another idea as how to handle this kind of > > thing? Is it not good code practice to have one property set a number > > of other properties? I could of course just do the SpreadTemplate = > > Pipeline on form load or some other place that only gets called during > > runtime, but I want to be able to see the changes at design time, so I > > can design the rest of the form. I am really baffled at this behaviour, > > please advise...! > > > Regards > > ...Seth- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -
Other interesting topics
Non-proportional (non Rectangular) resizing
Asynchronous Programming Model - how to implement? How to Create WinForms client and ClassLib server as one assembly? ComboBox updating data source via look-up table Disable a text box when it's not adding new row? Possible help for Newbie VS 2003, false data concurrency error Dataset and scalability issue vs 2003 to vs 2005 conversion problem Strange concurrency error |
|||||||||||||||||||||||