[Mono-bugs] [Bug 79095][Maj] New - Crash when setting TextBox.SelectionStart in a KeyPress event

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Aug 17 17:13:47 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by kuba.brecka at gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=79095

--- shadow/79095	2006-08-17 17:13:47.000000000 -0400
+++ shadow/79095.tmp.3566	2006-08-17 17:13:47.000000000 -0400
@@ -0,0 +1,103 @@
+Bug#: 79095
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: Windows XP
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: Windows.Forms
+AssignedTo: peter at novonyx.com                            
+ReportedBy: kuba.brecka at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Crash when setting TextBox.SelectionStart in a KeyPress event
+
+Using SVN head, the following code causes an exception with a crash as a
+consequence. The exception is throw in a drawing procedure of the TextBox.
+The line that causes the problem is marked in the code.
+
+The program should show a form and a textbox, when you type anything into
+the textbox, the program changes the first letter entered to be capital
+'A'. Under MS.NET it works fine, under Mono it causes a crash.
+
+I'm testing on Windows, but I suppose it happens on Linux also (someone
+should verify this).
+
+Exception stack:
+Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of
+range.
+  at System.Text.StringBuilder.ToString (Int32 startIndex, Int32 length)
+[0x00000] 
+  at System.Windows.Forms.Document.Draw (System.Drawing.Graphics g,
+Rectangle clip) [0x00000] 
+  at System.Windows.Forms.TextBoxBase.OnPaintInternal
+(System.Windows.Forms.PaintEventArgs pevent) [0x00000] 
+  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message m)
+[0x00000] 
+  at System.Windows.Forms.TextBoxBase.WndProc (System.Windows.Forms.Message
+m) [0x00000] 
+  at System.Windows.Forms.TextBox.WndProc (System.Windows.Forms.Message m)
+[0x00000] 
+  at System.Windows.Forms.Control+ControlNativeWindow.WndProc
+(System.Windows.Forms.Message m) [0x00000] 
+  at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg,
+IntPtr wParam, IntPtr lParam) [0x00000] 
+  at (wrapper native-to-managed) System.Windows.Forms.NativeWindow:WndProc
+(intptr,System.Windows.Forms.Msg,intptr,intptr)
+  at <0x00000> <unknown method>
+  at (wrapper managed-to-native)
+System.Windows.Forms.XplatUIWin32:Win32DispatchMessage
+(System.Windows.Forms.MSG&)
+  at System.Windows.Forms.XplatUIWin32.DispatchMessage
+(System.Windows.Forms.MSG msg) [0x00000] 
+  at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG
+msg) [0x00000] 
+  at System.Windows.Forms.Application.RunLoop (Boolean Modal,
+System.Windows.Forms.ApplicationContext context) [0x00000] 
+  at System.Windows.Forms.Application.Run (System.Windows.Forms.Form
+mainForm) [0x00000] 
+  at MonoTest19.Form1.Main () [0x00000] 
+
+
+Reproduce code:
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+
+namespace MonoTest19
+{
+    public class Form1 : Form
+    {
+        static void Main()
+        {
+            Application.Run(new Form1());
+        }
+
+        public Form1()
+        {
+            TextBox T = new TextBox();
+            T.Location = new System.Drawing.Point(10, 10);
+            T.KeyPress += new KeyPressEventHandler(T_KeyPress);
+            Controls.Add(T);
+        }
+
+        void T_KeyPress(object sender, KeyPressEventArgs e)
+        {
+            TextBox T = sender as TextBox;
+            if (T.SelectionStart == 0)
+            {
+                T.Text = "A";
+                e.Handled = true;
+
+                // this line causes the problem - though it doesn't crash
+on this line
+                // it seems it crashes when the TextBox draws itself
+                T.SelectionStart = 1;
+            }
+        }
+    }
+}


More information about the mono-bugs mailing list