Changing the text properties of a text box.
-
I am using a folderbrowserdialog to have the user browse for the location of a folder. Once it is located it is copied to a text box. Can I change the text properties of the text box so that path remains there? Thanks for any help. Darrall
I am not sure what you are trying to achieve, but if you want to put the path in a text box so teh user can't then change it, the set the ReadOnly property of the text box to true. The still leave the question: why put it in a text box if you don;t want the user to change it? Why not use something the user isn't used to changing - a label?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
I am not sure what you are trying to achieve, but if you want to put the path in a text box so teh user can't then change it, the set the ReadOnly property of the text box to true. The still leave the question: why put it in a text box if you don;t want the user to change it? Why not use something the user isn't used to changing - a label?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
It's not a matter of the user changing it - it's that I want it to still be there when the application is closed and reopened. The reason for this is there are text files that are in the program. When you create the text files they are assigned the full path of the application. To access those files I have to hard code the paths in the program. Now some other user stores it in his computer someplace different than me and the paths are all wrong. This way I use a folderbrowserdialog to find the path. I chose a textbox for convenience but the idea is to only have to do this once...not every time you open the application. If after doing it the first time if the properties of the textbox text are that path it is loaded right into the program. Hopes this makes sense.
-
It's not a matter of the user changing it - it's that I want it to still be there when the application is closed and reopened. The reason for this is there are text files that are in the program. When you create the text files they are assigned the full path of the application. To access those files I have to hard code the paths in the program. Now some other user stores it in his computer someplace different than me and the paths are all wrong. This way I use a folderbrowserdialog to find the path. I chose a textbox for convenience but the idea is to only have to do this once...not every time you open the application. If after doing it the first time if the properties of the textbox text are that path it is loaded right into the program. Hopes this makes sense.
- Right click your project, and select "Add...New Item...Application Configuration File" 2) Add a reference to "System.Configuration.dll", and import the System.Configuration namespace to your .CS file. 3) Double Click your app.config file, and make it look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyFieldName" value="MyField"/>
</appSettings>
</configuration>-
Load existing path with:
string s = ConfigurationManager.AppSettings\["MyFieldName"\];
-
Save new path with:
ConfigurationManager.AppSettings\["MyFieldName"\] = "MyFieldValue";
There are other ways to use application config in .NET, but that one is easy to explain!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
- Right click your project, and select "Add...New Item...Application Configuration File" 2) Add a reference to "System.Configuration.dll", and import the System.Configuration namespace to your .CS file. 3) Double Click your app.config file, and make it look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyFieldName" value="MyField"/>
</appSettings>
</configuration>-
Load existing path with:
string s = ConfigurationManager.AppSettings\["MyFieldName"\];
-
Save new path with:
ConfigurationManager.AppSettings\["MyFieldName"\] = "MyFieldValue";
There are other ways to use application config in .NET, but that one is easy to explain!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Please ignore the previous post - I was in a hurry, and cocked it up completely! Don't use App.Config, use Settings.Settings instead (App.config will work, but it is harder to save new values, the way I described does not work!) 1) Open your projects Properties in the solution explorer, and double click on "Settings.settings" 2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as sting and User respectively. 3) Save and close the settings window. 4) To read your setting:
string s = Properties.Settings.Default.MySetting;
-
To write your setting:
Properties.Settings.Default.MySetting = "My new setting value"; Properties.Settings.Default.Save();
Sorry about that - in my defence I was in hurry!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
-
Please ignore the previous post - I was in a hurry, and cocked it up completely! Don't use App.Config, use Settings.Settings instead (App.config will work, but it is harder to save new values, the way I described does not work!) 1) Open your projects Properties in the solution explorer, and double click on "Settings.settings" 2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as sting and User respectively. 3) Save and close the settings window. 4) To read your setting:
string s = Properties.Settings.Default.MySetting;
-
To write your setting:
Properties.Settings.Default.MySetting = "My new setting value"; Properties.Settings.Default.Save();
Sorry about that - in my defence I was in hurry!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
-
Thanks. Where do I write that code? I assume the information in quotes would be my information?
Anywhere you like! I would suggest loading the path into the TextBox on form load (and put it into the SelectedPath property of the FolderBrowserDialog as well). Then when the user presses the OK button in the FolderBrowserDialog, load up the TextBox, and save the new path. You can replace "MySetting" with your own name(s), and the same for "Defaulted value" and "My new setting value". So if you want a setting called "ThisIsThePathTheIdiotUserWantsMeToUse", you can, and access it via
string s = Properties.Settings.Default.ThisIsThePathTheIdiotUserWantsMeToUse;
However, I wouldn't recommend it as the settings file is in XML and is thus human readable... :laugh:
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Anywhere you like! I would suggest loading the path into the TextBox on form load (and put it into the SelectedPath property of the FolderBrowserDialog as well). Then when the user presses the OK button in the FolderBrowserDialog, load up the TextBox, and save the new path. You can replace "MySetting" with your own name(s), and the same for "Defaulted value" and "My new setting value". So if you want a setting called "ThisIsThePathTheIdiotUserWantsMeToUse", you can, and access it via
string s = Properties.Settings.Default.ThisIsThePathTheIdiotUserWantsMeToUse;
However, I wouldn't recommend it as the settings file is in XML and is thus human readable... :laugh:
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy