McKeymayker
McKeymayker

Reputation: 358

Saving Button location in XML file in Windows Form

My problem is Saving Button location in XML file. My Form have button that are draggable on edit form, so when i am finished editing the form i want to save Button location in XML file, so then i can read the location from the XML file and display the button on the modified position.

Any Suggestions?

Upvotes: 1

Views: 471

Answers (1)

Konamiman
Konamiman

Reputation: 50293

Unless it's otherwise a requirement for your application or you need to store additional complex data, you don't really need to create an XML file. You could use a plain text file like this:

var fileContents = string.Format("{0}\r\n{1}\r\n", button.Top, button.Left);
File.WriteAllText("ButtonCoordinates.dat");

Then to read and apply back the coordinates:

var fileContents = File.ReadAllLines("ButtonCoordinates.dat");
button.Top = double.Parse(fileContents[0]);
button.Left = double.Parse(fileContents[1]);

Of course you need to add error checking, file path management et al, but you get the idea.

Upvotes: 1

Related Questions