Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Seth Gecko - 26 Jan 2007 17:18 GMT
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
Stoitcho Goutsev (100) - 26 Jan 2007 17:59 GMT
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)]

Signature

HTH
Stoitcho Goutsev (100)

> Hi
>
[quoted text clipped - 66 lines]
> Regards
> ...Seth
Seth Gecko - 27 Jan 2007 12:30 GMT
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

On 26 Jan., 18:59, "Stoitcho Goutsev \(100\)" <1...@100.com> wrote:
> Seth,
>
[quoted text clipped - 77 lines]
> > Regards
> > ...Seth- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -
Stoitcho Goutsev (100) - 29 Jan 2007 15:11 GMT
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.

Signature

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

On 26 Jan., 18:59, "Stoitcho Goutsev \(100\)" <1...@100.com> wrote:
> Seth,
>
[quoted text clipped - 80 lines]
> > Regards
> > ...Seth- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.