PropertyBag in VB.NET?

  • Thread starter Thread starter HKSHK
  • Start date Start date
H

HKSHK

Hello everybody,

I am trying to re-write a VB5-ActiveX-control in VB.NET. I googled for
"PropertyBag in VB.NET" and found that the only way is serialization
(and writing the properties into a file). Now I wonder...

a) Do I have to include this file with my application?

b) If I use one control in various applications at the same time do
they overwrite that file if the file name is identical?

Thanks for your help!

Best Regards,

HKSHK
 
Hi there,
a) Do I have to include this file with my application?

That's all down to you and how your saving your properties. If your
just saving the last users settings then no, you can create it on the fly if
it doesn't exist, which is always the correct procedure to prevent any
filenotfound exceptions.

If the file contains vast ammounts of complex information that you don't
want to have to create via code then simple store it in the application ass
a resource and if a settings file doesn't exist, dump it.
b) If I use one control in various applications at the same time do
they overwrite that file if the file name is identical?

Are you referring to saving the properties of a control during
design-time? If so don't worry, this is all handled for you automatically
within the forms automatically generated designer code.

If you want to save per/user application settings then you might want to
look into creating simple XML documents to persist your settings. I have an
old example here...

http://www.npsoftware.co.uk/Tutorials/tut_data_persistence_XML.php

I hope this helps.

Nick.
 
Hi Nick,

Thanks for your reply. It helped a lot.

Now, there's just one more thing I wonder:
I know when I have to read the properties (from the settings file), but
how can I find out if the user changed a property at design time and
save the changes to the file? I want to avoid that the properties are
saved if they are made by code at run-time, but they should be saved if
they are made at design time.

Thanks in advance for your help!

Best Regards,

HKSHK
 
Hi there,
Now, there's just one more thing I wonder:
I know when I have to read the properties (from the settings file), but
how can I find out if the user changed a property at design time and
save the changes to the file? I want to avoid that the properties are
saved if they are made by code at run-time, but they should be saved if
they are made at design time.

Well this is done automatically for you, the properties that are
modified by the user are stored in the automatically generated code section,
which is hidden in 2005 (not quite sure where it is now).

One way of testing for a property change would be to add code to the Set
part of the property accessor. Check the value coming in and see if it
..Equals the current value, if not then set it and you now know that a change
was made, you could then save the properties to a file. I'm not sure what
kind of performance hit this might give the idea if you have allot of
properties in the control.

As for checking to see if you are in design-time or run-time I am unsure
of this. And unfortuantely do not have enough time to look into it right
now. AFAIK you need to be looking for the Context which the application is
running in. Anyway, I hope this helps.

Nick.
 
Back
Top