I have a image loaded in a picture box.When i click on the image there is some data(not required here) which will be stored in an XML file.But the problem is when ever i click the mouse on image, the data is getting over written.Instead i need to add the data that is obtained after every mouse click.here is my part of the program under MouseClick event.
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
float u = l[p + 1] - l[p];
float v = m[p + 1] - m[p];
float w = (e.Y - m[p]) / v; //subtract from latitude
float z = (e.X - l[p]) / u; //add to longitude.
float latmin = h[p] - w;
float longmin = j[p] + z;
A1 = e.X - c[p];
A2 = e.Y - d[p];
B1 = c[p + 1] - c[p];
B2 = d[p + 1] - d[p];
A = Math.Sqrt(Math.Pow(A1, 2) + Math.Pow(A2, 2));
B = Math.Sqrt(Math.Pow(B1, 2) + Math.Pow(B2, 2));
dotproduct = A1 * B1 + A2 * B2;
theta = (180 / Math.PI) * Math.Acos( dotproduct / (A * B));
if (e.X < c[p])
{
theta1 = 360 - theta;
}
else
{
theta1 = theta;
}
MessageBox.Show(string.Format(" Latitude:{0}°{1:0.0}'\n Longitude:{2}°{3:0.0}' \n ICAO LOC: {4} {5}", g[p] + (int)latmin / 60, latmin % 60, i[p] + (int)longmin / 60, longmin % 60, textBox1.Text, Math.Abs((int)theta1)));
using (XmlWriter writer = XmlWriter.Create(string.Format("{0}.xml", textBox2.Text)))
{
writer.WriteStartDocument();
writer.WriteStartElement("WayPoints");
writer.WriteStartElement("Latitude");
writer.WriteElementString("Degrees",XmlConvert.ToString( g[p] + (int)latmin / 60));
writer.WriteElementString("Minutes", XmlConvert.ToString(latmin % 60));
writer.WriteEndElement();
writer.WriteStartElement("Longitude");
writer.WriteElementString("Degrees", XmlConvert.ToString(i[p] + (int)longmin / 60));
writer.WriteElementString("Minutes", XmlConvert.ToString(longmin % 60));
writer.WriteEndElement();
writer.WriteStartElement("IcaoLocator");
writer.WriteElementString("Type", textBox1.Text);
writer.WriteElementString("Angle", XmlConvert.ToString(Math.Abs((int)theta1)));
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
}
}
The file name of the XML is taken from the text in the textbox2.
Please give me some suggestion ,such that i can store data of all mouseclicks in one file.