When i run my program and click on the second tab multiple times it creates labels x amount of times and im unsure if theirs a way to sort of only read the xml only once… I tried using a .close method but that did not work for me… any help would be appreciated thank you
private void tabPage2_Enter(object sender, EventArgs e)
{
if (tabControl1.SelectedTab == tabPage2)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("xmldoc.xml");
foreach (XmlNode node in xmlDoc.SelectNodes("check/tick/mark"))
{
Label l = new Label();
System.Drawing.Point l1 = new System.Drawing.Point(65, 48 + a);
l.Location = l1;
l.Text = node.SelectSingleNode("score").InnerText;
tabPage2.Controls.Add(l);
a += 25;
}
}
}
Do the xml reading in a different function. Create a variable to store whether or not you have already read the xml. Only invoke the xml reading function if it has not already been called.