if i have:
Point a = new Point(10,10);
Object b = (object)a;
how can i get values (10 and 10) from 'b' object?
somthing like this:
Point c = new Point();
c.X = B.X;
in my case, i need to return a Point value... and in pseudocode is:
return (System.Drawing.Point)b;
or some hints please... thanks
Loading
Kirtan PatelPosted Nov 7, 2009, 5:26 AM
You can Convert string To point By PointConvert Class
using System.Drawing;
private void button1_Click(object sender, EventArgs e)
{
PointConverter converter = new PointConverter();
//Operation Needed to Perform Before converting String to Point
string stringData = "{X=10, Y=10}".Replace("=",string.Empty).Replace("X",string.Empty).Replace("Y",string.Empty).Replace("{",string.Empty).Replace("}",string.Empty);
//Convert to Point
Point p = (Point)converter.ConvertFromString(stringData);
//Use it
MessageBox.Show(string.Format("X={0} and Y={1}", p.X, p.Y));
}
if my Answer Helps you then mark "Do you like this answer" please :)
nonePosted Nov 7, 2009, 4:07 AM
if i print out my point
Point a = new Point(10,10);
Conole.WriteLine(a.ToString());
// Result:
// {X=10, Y=10}
now... my first object read a string from a Point.
b contain {X=10, Y=10} but it`s a string object. now... how can i substract values from string object? something like "convert string to point"... I wanna know if there are some function for that or i have to made this alone
thanks again
Jorge L FernandezPosted Nov 6, 2009, 4:53 PM
Point a = new Pont(10,10);
object b = a; // YOU DONT NEED TO CAST a AS OBJECT. a IS ALREADY AN OBJECT
Point c = new Point( ((Point)b).X, ((Point)b).Y);
or
Point c = (Point)b; // YOU WILL GET A COPY OF b SINCE POINT IS A STRUCT (VALUE TYPE)
Your pseudo code was fine. Just need to place the appropriate parenthesis when casting.