Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Changing the text properties of a text box.

Changing the text properties of a text box.

Scheduled Pinned Locked Moved C#
helpquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darrall
    wrote on last edited by
    #1

    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

    OriginalGriffO 1 Reply Last reply
    0
    • D Darrall

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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

        D Offline
        D Offline
        Darrall
        wrote on last edited by
        #3

        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.

        OriginalGriffO 1 Reply Last reply
        0
        • D Darrall

          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.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4
          1. 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>

          1. Load existing path with:

                 string s = ConfigurationManager.AppSettings\["MyFieldName"\];
            
          2. 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

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          D 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff
            1. 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>

            1. Load existing path with:

                   string s = ConfigurationManager.AppSettings\["MyFieldName"\];
              
            2. 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

            D Offline
            D Offline
            Darrall
            wrote on last edited by
            #5

            Thanks very much for all your time :) I'll try what you just sent me.

            OriginalGriffO 1 Reply Last reply
            0
            • D Darrall

              Thanks very much for all your time :) I'll try what you just sent me.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              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;
              
              1. 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

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              D 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                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;
                
                1. 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

                D Offline
                D Offline
                Darrall
                wrote on last edited by
                #7

                Thanks. Where do I write that code? I assume the information in quotes would be my information?

                OriginalGriffO 1 Reply Last reply
                0
                • D Darrall

                  Thanks. Where do I write that code? I assume the information in quotes would be my information?

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  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

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  D 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    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

                    D Offline
                    D Offline
                    Darrall
                    wrote on last edited by
                    #9

                    Ok Great! Thanks for all your help :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups