15 Ekim 2016 Cumartesi

Settings Sınıfı

Giriş
Settings bilgisi proje içinde App.config dosyasında saklanır. Bu dosyayı elle değiştirebileceğimiz gibi GUI kullanarak ta değiştirebiliriz. GUI kullanmak için şöyle yaparız.

"Right click your project >> Navigate to Properties >> Settings"

App.config
İskeleti şöyledir.
<configuration>

  <userSettings>
    <DemoApp.Properties.Settings>
      ...
    </DemoApp.Properties.Settings>
  </userSettings>

  <applicationSettings>
    <DemoApp.Properties.Settings>
     ...
    </DemoApp.Properties.Settings>
  </applicationSettings>

</configuration>
applicationSettings değiştirilemez. Açıklaması şöyle
Application-scope settings are read only, and can only be changed at design time or by altering the .exe.config file in between application sessions. User-scope settings, however, can be written at run time, just as you would change any property value. The new value persists for the duration of the application session. You can persist changes to user settings between application sessions by calling the Settings.Save method.
Constructor
Settings sınıfına şöyle erişiriz.
Properties.Settings.Default;
Okumak İçin Alana Erişmek 
Şöyle yaparız.
var empNameVal = Properties.Settings.Default.EmployeeName;
Yazmak İçin Alana Erişmek
StringCollection tipi için  şöyle yaparız.
Properties.Settings.Default[1] = cboEmpName.Text;
int tipi için şöyle yaparız.
Properties.Settings.Default.MessageNum++;
Save metodu
Şöyle yaparız. Bilgiler <AssemblyName>.exe.config dosyasında saklanır.
Properties.Settings.Default.Save();

Hiç yorum yok:

Yorum Gönder