Studio 2005 and the ".Designer" file...?!? Code practice in properties.

S

Seth Gecko

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
 
S

Stoitcho Goutsev \(100\)

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 said:
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
 
S

Seth Gecko

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

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)



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 -
 
S

Stoitcho Goutsev \(100\)

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)


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

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)

message

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 -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top