From: Martin Honnen on 11 Apr 2010 14:14 Tony Johansson wrote: > "Martin Honnen" <mahotrash(a)yahoo.de> skrev: >> Tony Johansson wrote: >>> When I run the code below I get runtime error saying >>> 10,10,100,200 is not a valid value for Int32. >>> But I mean this method ConvertFromString can take a string and convert >>> that to a rectangle that's what the docs say >>> So is there a bug or have I missunderstood this ConvertFromString ? >>> >>> protected override void OnPaint(PaintEventArgs e) >>> { >>> string rectInput = "10,10,100,200"; >>> Graphics g = e.Graphics; >>> RectangleConverter converter = new RectangleConverter(); >>> Rectangle outerRect = (Rectangle) >>> converter.ConvertFromString(rectInput); >> It might depend on the current CultureInfo how that string is parsed >> respectively what format is expected. Does using >> ConvertFromInvariantString give you the result you want? > If I use ConvertFromInvariantString it works but I mean a rectangle always > look the same no matter what culture we use. I am not very familiar with the RectangeConverter class and those methods but as both ConvertFromString and ConvertFromInvariantString exist and as ConvertFromString has an overload http://msdn.microsoft.com/en-us/library/2kf8exy6(v=VS.90).aspx taking a CultureInfo it looks as if ConvertFromString is culture dependant. -- Martin Honnen --- MVP Data Platform Development http://msmvps.com/blogs/martin_honnen/
From: Tony Johansson on 11 Apr 2010 15:48 > As it happens, the string you're using matches the format expected by the > invariant culture. So it works when you use the > ConvertFromInvariantString() method. You could also get it to work by > determining what your current culture is and figuring out what format that > culture expects (though, if you're doing this for serialization purposes, > the invariant culture is actually a more appropriate choice anyway). > Hi! My current culture is swedish and this culture use ; as list separator and not ,(comma) so I just changed from , to ; and now it works. myRectangle.Location = (Point)pointConverter.ConvertFromString("20; 20"); myRectangle.Size = (Size)sizeConverter.ConvertFromString("200; 400"); I didn't thought about the list separator was culture dependent. //Tony
From: Patrice on 11 Apr 2010 15:40 > If I use ConvertFromInvariantString it works but I mean a rectangle always > look the same no matter what culture we use. "10,10,100,200" is just a string. Here in France , is used as the decimal point so ; is used to separate items. Likely the same in your country... So the culture does matter... -- Patrice
First
|
Prev
|
Pages: 1 2 Prev: about painting where I don't specify a rectangle Next: PGP keys in C# app |