6

I have an overriden (WinForms) MemoEdit control (unfortunately I can't give you the code). If I enter more than 32000 characters, it raises an error "A generic error occurred in GDI+" I thought that there's an error (exception) in my control but then I tested on a simple WinForm application this code:

var myString = new string('G', 32001);
var g = this.CreateGraphics();
g.MeasureString(myString, Font, 1000);

and it crashes with the same exactly error Does anyone know why this happens or where is specified this constant of 32000 ? I couldn't find anything useful on Google.

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

2

This seems to be a new bug which was introduced in Windows 8. I would be curious as to the behaviour in an older version of Windows:

https://connect.microsoft.com/VisualStudio/feedback/details/776722/label-control-throws-an-exception-if-its-text-is-set-to-a-very-long-string

Frank Hileman
  • 1,159
  • 9
  • 19
  • This link is broken. Any idea if there's a new link to this issue? – Tim Andersen Sep 29 '15 at 21:11
  • They don't want to fix it, is my understanding. The last two posts can be found on a cached version of the web page. http://webcache.googleusercontent.com/search?q=cache:LHbEaBO6c-EJ:https://connect.microsoft.com/VisualStudio/feedback/details/776722/label-control-throws-an-exception-if-its-text-is-set-to-a-very-long-string – Frank Hileman Oct 01 '15 at 22:25
  • Thanks for the link to the cached page, Frank. Well, that doesn't bode well for the new bug report I just opened a couple days ago (https://connect.microsoft.com/VisualStudio/feedback/details/1850428/graphics-measurestring-throws-exceptions-for-long-strings-in-win8-didnt-in-previous-versions-of-windows). We're running into this issue on any Win8 or later machine, which seems to jive with this other bug post's explanation. I haven't gotten a response yet from MS, but I'm doubtful I'll like their answer... – Tim Andersen Oct 02 '15 at 02:46
0

It could be possible that the string width exceeds Int32.Max (you could maybe refer to this thread).

I know that your error occures if you use a language as Arabic which involves special characters (see MSDN-Link: For bidirectional languages, such as Arabic, the string length must not exceed 2046 characters).

To solve your problem I would suggest splitting the string every 31999th character and add the different sizes/lengths.

unknown6656
  • 2,765
  • 2
  • 36
  • 52
  • 32000 != 32k. Also: it is the MeasureString that crahes, not the string assignment.. – TaW May 31 '15 at 11:40
  • @TaW: I know that, I meant that the string width **in pixel** larger is than Int32 – unknown6656 May 31 '15 at 14:03
  • Yeah, well, it is curious though: 32000 does work and 32001 does not. There is no string width in pixel other than the 1000 pixels he feeds into the MeasureString. And the resulting height (which is what he actually measures) is a few hundred pixels, depending on the font. The sources lead into a core routine, passing in the length as int.. rather weird. – TaW May 31 '15 at 14:24
  • I'm using English as a language. I haven't tried any other languages. – Victor George Cojocaru Jun 01 '15 at 13:08