i have a wierd error in my code. The thing i want to do is, when i close and open the program, i want to see the toolstrips at their last locations.
this method load coordinates of two toolstrip from an xml file into a datatable, then i hold the values in coordinate as point type. And then, i want to assign the coordinate values to location of toolstrips, but it does not work correct :S
public void LoadToolstripCoordinates()
{
int i;
Point coordinates = new Point();
DataTable dTable = new DataTable();
dTable = ReadLogFromXml();
if (dTable != null)
{
for (i = 0; i < dTable.Rows.Count; i++)
{
coordinates.X = Convert.ToInt32(dTable.Rows[i][1]);
coordinates.Y = Convert.ToInt32(dTable.Rows[i][2]);
if (loading == 0)
{
//here code does not work correct
if (i == 0) this.toolStrip1.Location = new System.Drawing.Point(coordinates.X,coordinates.Y);
if (i == 1) this.toolStrip2.Location = new System.Drawing.Point(coordinates.X,coordinates.Y);
}
}
loading=1;
}
}
this.toolStrip1.Location has x and y values,when i debug my code, i saw that x value changes but y value does not change. i couldn't understand the problem, if u have any idea, please inform me
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Feb 6, 2010, 2:45 AM
Here is Code I have Written For you !!Take a Reference of it Download the Attachment of Post .
and do check "Do you like this answer" check box please :)
namespace ControlTrackingXML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void WriteLocationToFile()
{
int x = toolStrip1.Location.X;
int y =toolStrip1.Location.Y;
XmlTextWriter wr = new XmlTextWriter("condination.xml", Encoding.UTF8);
wr.WriteStartDocument();
wr.WriteStartElement("Condinates1");
wr.WriteAttributeString("x", x.ToString());
wr.WriteAttributeString("y", y.ToString());
wr.WriteEndElement();
wr.WriteEndDocument();
wr.Close();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
WriteLocationToFile();
}
private void Form1_Load(object sender, EventArgs e)
{
// Load Location of ToolStrip from File
XmlDocument doc = new XmlDocument();
doc.Load("condination.xml");
foreach (XmlNode n in doc.ChildNodes)
{
if (n.Name == "Condinates1")
{
int x, y;
x = Convert.ToInt32(n.Attributes["x"].Value.ToString());
y = Convert.ToInt32(n.Attributes["y"].Value.ToString());
toolStrip1.Location = new Point(x, y);
}
}
}
}
}
Kirtan PatelPosted Feb 6, 2010, 2:39 PM
billypostmanPosted Feb 6, 2010, 11:37 AM
billypostmanPosted Feb 5, 2010, 4:50 PM
Charbel AbdoPosted Feb 4, 2010, 10:43 AM