Retaining dynamically added labels even when application isrestarted.

K

ketaki

Hello,
I am facing a problem. I have a application in C# (winforms) where
I am giving an option to the user to add labels during runtime. But
when the application is restarted the labels that are added
during runtime get deleted. As the user is adding a label I do not
know the location of label. I want the labels added to appear in the
same location even when the application is restarted.
Please help.
Thanks
 
C

cfps.Christian

I did something similar only with buttons. What I did was created an
object that told me the information I needed to know and serialized it
onto the user's hard drive. If you're working on a more enterprise
application you could do the same into a database. Once you've saved
it then just on the form load (in my case Log In) just grab the file
with the correct name (I based mine on user ID) and deserialize it
using the information to replace all the information.
 
P

Peter Duniho

Hello,
I am facing a problem. I have a application in C# (winforms) where
I am giving an option to the user to add labels during runtime. But
when the application is restarted the labels that are added
during runtime get deleted. As the user is adding a label I do not
know the location of label. I want the labels added to appear in the
same location even when the application is restarted.

If you have no way to enumerate the labels that were added (and thus find
out their location), then you won't be able to do this. So the first step
is to fix your design if necessary so that you can enumerate the added
labels.

Once you've done that, it's a simple matter to save the important
information (pretty much whatever the user has control over, which might
include text, position, font, color, whatever...you're pretty vague about
what's going on so I can't offer specifics). The question is "where to
save it?" You can write to a file or database as "cfps.Christian"
suggests, but I'd say that in the most basic scenarios, you should just
using the built-in Settings class and let .NET handle how to actually
manage the data persistence.

Pete
 

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