Click here to Skip to main content
15,078,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone, I want to set the text of label to default For example I run my appcation first time label1.text = "Hello Everyone" and I change it to label1.text = "Hello Programmer" and I close the appcation and then I open it again, Default text is "Hello Everyone" but I want it to show the text "Hello Programmer" and when I open this appcation again I will show "Hello Programmer" every time

How can I make it(What is the code?) ?
Member 11277077 2-Apr-15 10:11am
Sorry about my language because I am THAI but I and speak English
a little ...
Manoj K Bhoir 2-Apr-15 10:26am
Don't post any comment as solution. Please remove it.
Manoj K Bhoir 2-Apr-15 10:30am
It is very difficult to understand your question. If you want to set default text of label control as “Hello Programmer” then what is the problem? just set “Text” property of label control to “Hello Programmer” , so whenever you will run your application you will see “Hello Programmer”.

Sergey Alexandrovich Kryukov pointed out "you need to persist the text". From your example, the values "Hello everyone" and "Hello Programmer" might be considered a property to greet the end user. This is one method to accomplish this. You can use the My.Settings object. Create a field for my.settings.greetings as String.

In your code when the form loads:
Label1.Text = my.settings.greeting

When the form is closing:
My.settings.gtreetings = label1.Text

For more information on using the My.Setting Object see:
Ron O.
There is no such concept as default, in that sense. More exactly, the default is empty string, but you are talking about something else; and this is nothing but just setting some text to the label, just the opposite, not default, but new text. You are talking about showing different text after you start the same application again. It means that you need to persist the text. In other words, write the current states to some file and read it when the application started. Where to write it and read from? Your application should behave nicely and not contaminate the OS with its data file and, at the same time, not face access violation. So, you can use so called "special folder". Please see my past answers:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

Manoj K Bhoir 2-Apr-15 10:45am
OMG :o. Sergey Alexandrovich Kryukov you deserve my 5 for only understanding that question. :)
Thank you, Manoj.
Member 11277077 2-Apr-15 10:49am
Thank You very mush for your answer
You are welcome. Will you accept the answer formally then?
Please help me Please................
And you don't abuse forum posting, please... This is not an answer. Please remove it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900