c# - How to display the values from an app.config file -


i have loop increments , display increment number when mouse hovers on button. values each button stored in app.config file.how use incremented value show correct value name?

current code

public void controls() {     (int = 1; <= applications; i++)     {         string iconpath = configurationmanager.appsettings["application"+i+"_icon"];         button button = new button();          this.controls.add(button);         top += button.height+25;         button.tag = i;         button.mousehover += button_mousehover;         button.mouseleave += button_mouseleave;         button.visible = true;          button.click += new eventhandler(button_click);    } 

app.config:

 <appsettings>   <add key="applications" value="3" />    <add key="catergory" value="1"/>   <add key="application1_name" value="word"/>   <add key="application1_executable_name" value="word.exe"/>   <add key="application1_autoclose" value="true"/>   <add key="application1_icon" value="c:\pictures\images.png"/>     <add key="catergory" value="1"/>   <add key="application2_name" value="paint"/>   <add key="application2_executable_path" value="c:\windows\system32\"/>   <add key="application2_autoclose" value="true"/>   <add key="application2_icon" value="c:\pictures\images.png"/>     <add key="catergory" value="1"/>   <add key="application3_name" value="notepad"/>   <add key="application3_executable_path" value="c:\windows\"/>   <add key="application3_autoclose" value="true"/>   <add key="application3_icon" value="c:\pictures\images.png"/>  </appsettings> 

currently when hover on button shows me values 1,2,3 want show me notepad, word, paint.

what tried

public void controls() {         (int = 1; <= applications; i++)         {             namevaluecollection sall;             sall = configurationmanager.appsettings;              button button = new button();              this.controls.add(button);             top += button.height+25;             button.tag = i;              foreach(string s in sall.allkeys)             {                 button.text = s + ;             }         } } 

what shows me 1,2,3 , paint displayed everything.

as need value of key you should following inside loop.

and doesn't need foreach loop.

just use following you

as using foreach loop, not required @ all.

so remove because increase time-complexity.

in case have multiple keys in app.config want of them should have specified format application_name like:

  • application_name1
  • application_name2
  • application_name3
  • application_name4

then following in code can add many buttons want adding key config file.

public void controls()     {             (int = 1; <= applications; i++)             {                 namevaluecollection sall;                 sall = configurationmanager.appsettings;                  button button = new button();                  this.controls.add(button);                 top += button.height+25;                 button.tag = i;                 button.text = sall["application_name"+i] ;             }     } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -