I defined a class in Form1 as
public class Conditions
{
public string name { get; set; }
public int probability { get; set; }
public DateTime start_time { get; set; }
public DateTime end_time { get; set; }
public int age_min { get; set; }
public int age_max { get; set; }
public bool meldpeld { get; set; }
public bool onea { get; set; }
public bool oneb { get; set; }
public int gender { get; set; } // 0 - both, 1 - male, 2 - female
public int meld_min { get; set; }
public int meld_max { get; set; }
}
and I’m making a new list like
List<Conditions> newconditions = new List<Conditions>();
Then, I’m calling Form2 with
Conditions newconds = new Conditions();
Form2 form2 = new Form2(newconds);
form2.Show();
form2.TopMost = true;
In Form2, I have
public Form2(Form1.Conditions newcond)
{
InitializeComponent();
comboBox1.SelectedIndex = 2;
}
and I can use set things for newcond in there
what I would like to do, however, is set things in another function in Form2 called
private void button2_Click(object sender, EventArgs e)
and I can’t figure out how to use the newcond in that function. I must be missing something obvious, right?
Also, is this a good way to go? Basically what I want to do is have the user define any number of conditions (that they can add, edit, delete) and then use those conditions when they run the program.
Thanks
You’re on the right track sort of.
Basically, I would move your Conditions class into it’s own file called Conditions.cs – this is best practice.
Then define a member variable in your class file for Form2. Then in your Constructor for Form2 set that member variable.
then you can use that in your click method: