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. Saving User and Application Settings in WinForms

Saving User and Application Settings in WinForms

Scheduled Pinned Locked Moved C#
csharpwinformshelpquestion
4 Posts 3 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.
  • S Offline
    S Offline
    Sokka93
    wrote on last edited by
    #1

    I want to save changes in my C# form. So I tried this. There are 3 buttons on my form but the code saves only button3's location. What should I do? Please help me!

    foreach (Button a in Form1.ActiveForm.Controls)
     {
     Properties.Settings.Default.SavedSetting3 = a.Location;
     }
    Properties.Settings.Default.Save();
    

    Thanks in advance

    A H 2 Replies Last reply
    0
    • S Sokka93

      I want to save changes in my C# form. So I tried this. There are 3 buttons on my form but the code saves only button3's location. What should I do? Please help me!

      foreach (Button a in Form1.ActiveForm.Controls)
       {
       Properties.Settings.Default.SavedSetting3 = a.Location;
       }
      Properties.Settings.Default.Save();
      

      Thanks in advance

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      You can save in one setting entry only one value. From what you are doing, you are trying to save 3 different locations to one setting entry(SavedSetting3) which is wrong. In each loop execution you are overwriting the last set value and hence, the value which is last written (button3 I guess) is the one which is saved. You will need to create 3 different setting's entry to save each of the buttons location.

      S 1 Reply Last reply
      0
      • A ABitSmart

        You can save in one setting entry only one value. From what you are doing, you are trying to save 3 different locations to one setting entry(SavedSetting3) which is wrong. In each loop execution you are overwriting the last set value and hence, the value which is last written (button3 I guess) is the one which is saved. You will need to create 3 different setting's entry to save each of the buttons location.

        S Offline
        S Offline
        Sokka93
        wrote on last edited by
        #3

        Thank you. What if I don't know how many buttons or controls exist? How can I create a setting for each control? I'm working on a programme that users can add controls at run time.

        1 Reply Last reply
        0
        • S Sokka93

          I want to save changes in my C# form. So I tried this. There are 3 buttons on my form but the code saves only button3's location. What should I do? Please help me!

          foreach (Button a in Form1.ActiveForm.Controls)
           {
           Properties.Settings.Default.SavedSetting3 = a.Location;
           }
          Properties.Settings.Default.Save();
          

          Thanks in advance

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          You can have these settings saved for you automatically. Just have a google for 'App.Config' or 'Saving Form Location' and read up about it.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          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