[MWF] Fix size of text area on message box (Fixes #2090)
authorEberhard Beilharz <eb1@sil.org>
Mon, 10 Mar 2014 15:45:10 +0000 (16:45 +0100)
committerEberhard Beilharz <eb1@sil.org>
Mon, 10 Mar 2014 15:45:10 +0000 (16:45 +0100)
Previously some characters might have been concatenated on a message
box that displayed an icon because the size of the text area was
calculated wrong. This fixes bug #2090
(https://bugzilla.xamarin.com/show_bug.cgi?id=2090).

mcs/class/Managed.Windows.Forms/System.Windows.Forms/MessageBox.cs

index f4bc41165e7a382b17305634e0a829ecb0bfdc1d..5e3b489a921b1ef7446e8832bc4632f08bce0d8f 100644 (file)
@@ -214,12 +214,14 @@ namespace System.Windows.Forms
                                int max_width = (int) (Screen.GetWorkingArea (this).Width * 0.6);
 
                                // First we have to know the size of text + image
-                               Drawing.SizeF tsize = TextRenderer.MeasureString (msgbox_text, this.Font, max_width);
+                               Drawing.SizeF tsize = TextRenderer.MeasureText (msgbox_text, this.Font, new Size (max_width, int.MaxValue), TextFormatFlags.WordBreak);
                                text_rect = new RectangleF ();
-                               text_rect.Size = tsize;
-                               
+                               text_rect.Height = tsize.Height;
+
+                               int iconImageWidth = 0;
                                if (icon_image != null) {
-                                       tsize.Width += icon_image.Width + 10;
+                                       iconImageWidth = icon_image.Width + 10;
+                                       tsize.Width += iconImageWidth;
                                        if(icon_image.Height > tsize.Height) {
                                                // Place text middle-right
                                                text_rect.Location = new Point (icon_image.Width + space_image_text + space_border, (int)((icon_image.Height/2)-(tsize.Height/2)) + space_border);
@@ -232,6 +234,7 @@ namespace System.Windows.Forms
                                        text_rect.Location = new Point (space_border + button_space, space_border);
                                }
                                tsize.Height += space_border * 2;
+                               text_rect.Height += space_border;
 
                                // Now we want to know the amount of buttons
                                int buttoncount;
@@ -284,6 +287,8 @@ namespace System.Windows.Forms
                                else
                                        this.ClientSize = new Size (tb_width + (space_border * 2), Height = new_size.Height + (space_border * 4));
 
+                               text_rect.Width = new_size.Width - iconImageWidth;
+
                                // Now we set the left of the buttons
                                button_left = (this.ClientSize.Width / 2) - (tb_width / 2) + 5;
                                AddButtons ();