Hi guys I'm wondering if this possible in some fashion?
I'm trying to create a settings object, and pass it around my forms in project.
Ultimate goal is to have my application title, which will appear on all forms title text, in app.config or user.config.
Program.cs
namespace TestApp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Properties.Settings settings = new Properties.Settings();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(settings));
}
}
}
Form1.cs
namespace TestApp
{
public partial class Form1 : Form
{
public Properties.Settings settings;
public Form1(Properties.Settings Settings)
{
settings = Settings;
InitializeComponent();
}
// use settings in other methods.
}
}
Form1.Designer.cs
namespace TestApp
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
// usual code
//
// Form1
//
this.Text = settings.AppTitle; // form title using app settings
//
// usual code
//
}
}
}
The 2 errors I get are the same and point to the following bold objects in Form1.cs
(edit) bold not working?public Properties.Settings **settings**;
(settings)
public **Form1**(Properties.Settings Settings)
(Form1)
The error is
error CS0052: Inconsistent accessibility: field type 'TestApp.Properties.Settings' is less accessible than field 'TestApp.Form1.settings'
I have searched the error, but those I found did not seem to relate to my problem and I do not really understand MS generic explanation.
I'm looking (a lot lately) for some education regarding this.
I appreciate you reading my post.