I am trying to save a form location to a database whenever the LocationChanged event is triggered on that form.
private void DisplayForm_LocationChanged(object sender, EventArgs e)
{
DSLocation = this.Location;
((Form1)this.MdiParent).NotifyChanges(this); // notify parent form that there are changes on this child
}
DSLocation is a property that I'm trying to fill with data from this.Location in order to pass it back to the parent form and ultimately the database. Whenever I try to compile, I get the error: Cannot implicitly convert type 'System.Drawing.Point' to 'string'
I know that I need to somehow break the coordinates coming from this.Location into two pieces and convert them into int and then recombine them into a string, but I have no idea how to go about this. My searches have only found tutorials and sites that talk about going from String to Point, not the reverse... Using those tutorials and examples I was able to get the coordinates formatted coming from the database:
private Point StringToPoint(string str)
{
string[] s = str.Split(',');
int x = Int32.Parse(s[0]);
int y = Int32.Parse(s[1]);
return new Point(x, y);
}
childForm.Location = StringToPoint((string)row["location"]);
...but I am not nearly knowledgeable enough to make the reverse happen.
Any of you bright people know how to juggle backwards?
-Charlie
Loading
Sam HobbsPosted Nov 25, 2010, 12:46 AM
Of course, I was not sure of the exact details of what you actually needed to do, but the following line would work the same as what you are using:
Charlie HoltPosted Nov 24, 2010, 11:34 PM
For anyone suffering the same problem, I ended up going with:
DSLocation = String.Format("{0},{1}", this.Location.X, this.Location.Y);
It works perfectly and is as condensed as I can get it.
-Charlie
Sam HobbsPosted Nov 24, 2010, 6:26 PM
((int)pt.X).ToString() + ',' + ((int)pt.Y).ToString()