Hey,
UPDATE: Solution 1 accepted!
I've been programming in C# for a few weeks (nearly fulltime) and learning every day. I am currently trying to organize the data in my project. This question is a followup question from my previous question
Passing data between forms. I have for example some settings which I want to adjust. These settings are used in the main form but set in a different form.
I'd like to have a central point in my project where I can store all my settings (variables). It is important that I can acces and update the data from all froms in my project.
I create for example a class with all the declarations with a default value. like this:
namespace SerialProgrammer
{
class Settings
{
public decimal Density = 21;
public string SelectedPrinterName = "ZDesigner GX430t";
}
}
So I want to adjust this value in form2; like this:
Settings settings = new Settings();
private void BTN_Set_Click(object sender, EventArgs e)
{
settings.Density = nudDensity.Value;
this.Close();
}
And on my main form I want to use the settings, like this:
Settings settings = new Settings();
private void printLabel(string snum, string type, int number)
{
if (IsPrinterOnline(settings.SelectedPrinterName))
{
if (settings.SelectedPrinterName.Contains(Dymo_PrinterName))
{
dymoPrintLabel(snum, type, number);
}
else if (settings.SelectedPrinterName.Contains(Zebra_PrinterName))
{
ZebraPrintLabel(snum, type, number);
}
}
}
What I experienced is that even though it looks like (at least for me) that both forms share the class Settings, they both use a different class Settings with different values. How can I change my code that I have one set of settings which are easily accessable from both forms?