473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ShouldSerialize question

Hi all,

In my Form1, I have this statement:

Me.EnhancedPanelGreen2.Background.Color =
System.Drawing.Color.GreenYellow

This is normal, because I've set to GreenYellow the Color property of the
class Background in the component EnhancedPanelGreen2.
Now, the following is the part of code of the class Background inside
EnhancedPanelGreen2 component that controls the serialization:

Public Property Color() As Color
Get
Return mColor
End Get
Set(ByVal value As Color)
mColor = value
End Set
End Property
' <Serialization>
Protected Sub ResetColor()
Color = Color.Green
End Sub
Protected Function ShouldSerializeColor() As Boolean
Return Not Color.Equals(Color.Green)
End Function

The problem is that changing Color to Green (that is the default of Color
property) in the property browser of Form1, the statement inside my Form1 IS
STILL:

Me.EnhancedPanelGreen2.Background.Color =
System.Drawing.Color.GreenYellow

What I need (and what I expected) is that the above statement will
disappears because the color (Green) is equal to the default(Green). Could
someone try to explain me what I'm missing?

Thank you very much

Carlo

Nov 21 '05 #1
6 2249
Hi Carlo,

I dont know - how does it relate to ShouldSerialize ?
Moreover, if you change any of the property of any control, the VS.NET
ide will generate code & put it in some specific location. e.g.
"InitializeComponent"

So, if you have hand-coded anything specific, it will not be replaced
by what you set from the properties window

Is that the case here ?

Kalpesh

Nov 21 '05 #2
Hi Kalpesh
this is not the case. I've changed Color Property to Green from within the
Property Window of the IDE. I simply expected that the statement with the
new color (Green) will disappears.
I've studied the problem from all the sides, finding no solutions


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
"Kalpesh" <sh*********@gmail.com> ha scritto nel messaggio
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi Carlo,

I dont know - how does it relate to ShouldSerialize ?
Moreover, if you change any of the property of any control, the VS.NET
ide will generate code & put it in some specific location. e.g.
"InitializeComponent"

So, if you have hand-coded anything specific, it will not be replaced
by what you set from the properties window

Is that the case here ?

Kalpesh

Nov 21 '05 #3
Hi Carlo,

Are you able to change the color using the property window ?
Before running the app, put a watch on whenever Color property changes.
This will help you identify - what is it that is resetting the color &
not taking your value at all

HTH
Kalpesh

Nov 21 '05 #4
Hi Kalpesh
the only problem is that the line

Me.EnhancedPanelGreen2.Background.Color = System.Drawing.Color.GreenYellow

is NOT removed by the designer when the color is set to Green.

Using the debugger not helped me to discover why.
If you have two or three minutes of patience, I can send you a very small
project that illustrates the problem.
Carlo


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
"Kalpesh" <sh*********@gmail.com> ha scritto nel messaggio
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi Carlo,

Are you able to change the color using the property window ?
Before running the app, put a watch on whenever Color property changes.
This will help you identify - what is it that is resetting the color &
not taking your value at all

HTH
Kalpesh

Nov 21 '05 #5
Hello Carlo,

You may not like this, but the solution in .net 1.1 is to write your
components in C#. I have seen the same bug when using Visual Basic as well.
It is confined to the use of value types. I was unable to find a work-around
either.

We try to use C# as much as possible, but if a customer demands a component
in VB, they simply have to live with the extra line of generated code, and
the bolded text in the PropertyGrid.

C# has other advantages for component libraries, such as the xml code
documentation that provides excellent intellisense and ndoc input.

Only the component author has to use C#; the component user can use VB.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Carlo" <ca************@gmail.com> wrote in message
news:u0**************@TK2MSFTNGP14.phx.gbl...
Hi Oliver
yes, I tried all the obvious things first: changing property names, using
variables instead of fixed values (i.e. Color.Green), changing scope of
Raset/ShouldSerialize, and so on.
In other words, I started to think to a bug when I noted the same
unexpected behaviour with any type, not only colors. In fact, the problem
I described in my post occours either with other types. In my sample
program, I'm using a Color type and a Boolean, and the problem is the
same.
I confirm that this afternoon I installed VS2005/beta2 and the line

Me.EnhancedPanelGreen2.Background.Color = System.Drawing.Color.GreenYellow

is removed after changing the color from GreenYellow to Green.

I'm developing a collection of GDI+ objects (components), and I use the
same base classes (i.e. Background class) for several components, and I
need have different defaults for backgrounds of each component.
Unfortunately, changing default of the base class (Background) from within
a component is reverted to Background class default after serialization.


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
"Oliver Sturm" <ol****@sturmnet.org> ha scritto nel messaggio
news:xn***************@msnews.microsoft.com...
Carlo wrote:
today I read here

http://msdn.microsoft.com/library/de...ustcodegen.asp

that the better practice is to set Resetxxx and ShouldSerializexxx to
private.


Yes, I guess that's right as a general practice. I don't actually use
these on a regular basis and I seemed to remember seeing many examples
where these methods were public.
Anyway, I've just tried THE SAME source on VS2005beta2 and IT WORKS
correctly! When the color is Green, the statement in Form1 is correctly
deleted.

Now, I must find a valid workaround for VS2003.


That's interesting. I'm quite sure I've done the same thing in VS 2003,
so there must be something special about the exact code you're using that
triggers this issue. Maybe you should try the obvious things first, like
changing the property's name or type to see when the problem goes away.
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


Nov 21 '05 #6
Hello Frank
today I've sent to Oliver Sturm (see this ng thread) a small program that
demonstrates my problem with serialization. He promptly reported me that the
problem does not occurred on his system (even if I'm absolutely sure that
the problem exists). So, I started to think that the problem is caused by
the localized version of VS (VB designer) that I'm currently using
(Italian). So, at the moment I'm planning to test an English version of IDE
today.

Now you say that you had the same problem with VB, and now I got confused!

About your suggestion: I know the advantages of C#. Unfortunately, I'm not
enought familiar with C# for programing a high-quality components collection
as I'm doing. I'm studying C#, and I plan to switch to C# in the next
half-year.

If the English version of the IDE will not solve my problem, I will adopt
the drastic workaround of not using defaults for some values, accepting bold
text in property browser.

Thank you for your help.

Carlo

-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
"Frank Hileman" <fr******@no.spamming.prodigesoftware.com> ha scritto nel
messaggio news:e5*************@TK2MSFTNGP12.phx.gbl...
Hello Carlo,

You may not like this, but the solution in .net 1.1 is to write your
components in C#. I have seen the same bug when using Visual Basic as
well. It is confined to the use of value types. I was unable to find a
work-around either.

We try to use C# as much as possible, but if a customer demands a
component in VB, they simply have to live with the extra line of generated
code, and the bolded text in the PropertyGrid.

C# has other advantages for component libraries, such as the xml code
documentation that provides excellent intellisense and ndoc input.

Only the component author has to use C#; the component user can use VB.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Carlo" <ca************@gmail.com> wrote in message
news:u0**************@TK2MSFTNGP14.phx.gbl...
Hi Oliver
yes, I tried all the obvious things first: changing property names, using
variables instead of fixed values (i.e. Color.Green), changing scope of
Raset/ShouldSerialize, and so on.
In other words, I started to think to a bug when I noted the same
unexpected behaviour with any type, not only colors. In fact, the problem
I described in my post occours either with other types. In my sample
program, I'm using a Color type and a Boolean, and the problem is the
same.
I confirm that this afternoon I installed VS2005/beta2 and the line

Me.EnhancedPanelGreen2.Background.Color =
System.Drawing.Color.GreenYellow

is removed after changing the color from GreenYellow to Green.

I'm developing a collection of GDI+ objects (components), and I use the
same base classes (i.e. Background class) for several components, and I
need have different defaults for backgrounds of each component.
Unfortunately, changing default of the base class (Background) from
within a component is reverted to Background class default after
serialization.


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
"Oliver Sturm" <ol****@sturmnet.org> ha scritto nel messaggio
news:xn***************@msnews.microsoft.com...
Carlo wrote:

today I read here

http://msdn.microsoft.com/library/de...ustcodegen.asp

that the better practice is to set Resetxxx and ShouldSerializexxx to
private.

Yes, I guess that's right as a general practice. I don't actually use
these on a regular basis and I seemed to remember seeing many examples
where these methods were public.

Anyway, I've just tried THE SAME source on VS2005beta2 and IT WORKS
correctly! When the color is Green, the statement in Form1 is correctly
deleted.

Now, I must find a valid workaround for VS2003.

That's interesting. I'm quite sure I've done the same thing in VS 2003,
so there must be something special about the exact code you're using
that triggers this issue. Maybe you should try the obvious things first,
like changing the property's name or type to see when the problem goes
away.
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)



Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
1
by: The Tarm | last post by:
hi, I have two classes, one base : Item and the other derived Group. Group is derived from Item. Item has a bunch of properties that are exposed through a PropertyGrid.SelectedObject. Now each of...
16
by: =?Utf-8?B?U3RldmUgQmFya2Vy?= | last post by:
WCF Question Hi guys, I’m pretty new to WCF, and have a basic question about how it works. I’m trying to use WCF to write an “SOA-system”, and am having a few problems. The...
6
semanticnotion
by: semanticnotion | last post by:
Hi sir i want to transform the data of one table into another through foreign key but the following error come to my browser Here is my code and data base structure. CREATE TABLE IF NOT...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.