Сохранение настроек программы в самом приложении - C#
Формулировка задачи:
Хочу спросить вас о сохранении настроек приложения в самом приложении.
Здесь нашёл статью: http://progs.biz/csharp/win/lessons/028.aspx
Написал код как там написано:
Но C# не 2008 не 2010 не видит сам этот settingsError:
Помогите открыть доступ/исправить баг что бы всё работало...
Ну или альтернативный способ.
Заранее спасибо!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Color color;
string firstName;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Новые значения для настроек.
color = Color.MediumPurple;
firstName = "Igor";
Invalidate();
// Запись настроек.
settings.MyColor = color;
settings.FirstName = firstName;
settings.Save();
}
private void button2_Click(object sender, EventArgs e)
{
// Новые значения для настроек.
color = Color.Firebrick;
firstName = "Roman";
Invalidate();
// Запись настроек.
settings.MyColor = Color.Firebrick;
settings.FirstName = firstName;
settings.Save();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
// Восстановление настроек.
color = settings.MyColor;
firstName = settings.FirstName;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
// Использование настроек.
Graphics g = e.Graphics;
Font font = new Font("Arial", 10);
g.DrawString(firstName, font, new SolidBrush(color), 100, 100);
}
}
}The name 'settings' does not exist in the current context
Решение задачи: «Сохранение настроек программы в самом приложении»
textual
Листинг программы
using System;
using System.IO;
public class Settings
{
protected string name;
protected string color;
protected string fname="settings.inf";
public string Name
{
get{
return name;
}
set{
this.name=value;
}
}
public string Color
{
get{
return color;
}
set{
this.color=value;
}
}
public void Load()
{
TextReader tr=new StreamReader(fname);
name=tr.ReadLine();
color=tr.ReadLine();
tr.Close();
}
public void Save()
{
TextWriter tw=new StreamWriter(fname);
tw.WriteLine(name);
tw.WriteLine(color);
tw.Close();
}
}
class MyClass
{
static void Main()
{
string name="KHAN";
string color="BLACK";
Console.WriteLine("Working with APP Settings");
Settings appSet=new Settings();
appSet.Name=name;
appSet.Color=color;
appSet.Save();
}
}