Converting a string array to a system.drawing.point array

Question

• With no success, i am trying to convert a string array to at point array. I have tried the code below, but I get the message - 'Value of type 1-dimensonal array of strings cannot be converted to system.drawing.point'.

Is there a way to do this conversion ??

Dim _point(2) As String

_point(0) = "50, 50"

_point(1) = "100, 25"

_point(2) = "200, 5"

Dim _curv As Point()

_curv = CType(_point, Point)

Dim g As Graphics = Me.CreateGraphics

g.FillPolygon(Brushes.AliceBlue, _curv)

Friday, January 27, 2006 9:36 AM

• You can't just cast it. You must convert it:

Here is the converted VB.NET code i converted from my writen C# code:
 Dim _point(2) As String_point(0) = "50, 50"_point(1) = "100, 25"Dim _curv(_point.Lenght) As Point Dim i As IntegerFor  i = 0 To  _poInteger.Lenght- 1  Step  i + 1    Dim chunks() As String =  _point(i).Split(',')     Dim x As Integer =  Convert.ToInt32(chunks(0).Trim())     Dim y As Integer =  Convert.ToInt32(chunks(1).Trim())      _curv(i) = New Point(x, y)Next

Here is the original C# code:
 string[] _point = new string[2]_point[0] = "50, 50";_point[1] = "100, 25";Point[] _curv = new Point[ _point.Lenght ];for( int i = 0; i < _point.Lenght; i++ ){    string[] chunks = _point[ i ].Split(',');    int x = Convert.ToInt32( chunks[ 0 ].Trim() );    int y = Convert.ToInt32( chunks[ 1 ].Trim() );        _curv[ i ] = new Point( x, y );}

Friday, January 27, 2006 9:52 AM
• You can use the class:

System.Drawing.PointConverter

Sample:

PointConverter pc = new PointConverter();

Point myPoint = (Point) pc.ConvertFromString(pointString);

Friday, January 27, 2006 9:55 AM

All replies

• You can't just cast it. You must convert it:

Here is the converted VB.NET code i converted from my writen C# code:
 Dim _point(2) As String_point(0) = "50, 50"_point(1) = "100, 25"Dim _curv(_point.Lenght) As Point Dim i As IntegerFor  i = 0 To  _poInteger.Lenght- 1  Step  i + 1    Dim chunks() As String =  _point(i).Split(',')     Dim x As Integer =  Convert.ToInt32(chunks(0).Trim())     Dim y As Integer =  Convert.ToInt32(chunks(1).Trim())      _curv(i) = New Point(x, y)Next

Here is the original C# code:
 string[] _point = new string[2]_point[0] = "50, 50";_point[1] = "100, 25";Point[] _curv = new Point[ _point.Lenght ];for( int i = 0; i < _point.Lenght; i++ ){    string[] chunks = _point[ i ].Split(',');    int x = Convert.ToInt32( chunks[ 0 ].Trim() );    int y = Convert.ToInt32( chunks[ 1 ].Trim() );        _curv[ i ] = new Point( x, y );}

Friday, January 27, 2006 9:52 AM
• You can use the class:

System.Drawing.PointConverter

Sample:

PointConverter pc = new PointConverter();

Point myPoint = (Point) pc.ConvertFromString(pointString);

Friday, January 27, 2006 9:55 AM