i want to write a program that somehow is like a designer where user can add textbox on the form and everything the user put into those textbox can be saved (like a setting) and after closing and opening the form again textboxs' text will remail unchanged.
so i decided to make a setting in project->settings and then make an array of it in my code. but whenever i want to access my settings it gives me an exception:
"An unhandled exception of type 'System.NullReferenceException' occurred in FormDesigner.exe"
here is my code from defining the array:
Settings[] formsetting=new Settings[3];
and here is my code for handling the textchanged event for everytext box: (i use the textboxs' tag to match the settings index with every textbox)
void t_TextChanged(object sender, EventArgs e)
{
TextBox temp = (TextBox)sender;
int s =(int) temp.Tag;
string str = temp.Text;
frmsetting[s].text = str;
}
the last line is where i get the error.
could someone explain to me what is the problem and how to fix it? and if my way is wrong could you please show my another way of doing this. thanks
You haven't initialized the objects in the array.
Doing this:
..creates the array. All 3 are
null
though. Do this: