[Mono-bugs] [Bug 425725] New: RichTextBox - Firing of Events differs to MS

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Sep 12 01:59:53 EDT 2008


User johnm at hlaustralia.com.au added comment

           Summary: RichTextBox - Firing of Events differs to MS
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: johnm at hlaustralia.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

Created an attachment (id=239208)
 --> (https://bugzilla.novell.com/attachment.cgi?id=239208)
Proposed Fix

Description of Problem:

The TextChanged and SelectionChanged events do not execute in the same order to
the Microsoft .NET framework.

Additionally Appending Text should not fire the SelectionChanged event at all.

using System;
using System.Windows.Forms;

public class test
        static void Main ()
                Form f = new Form ();

                RichTextBox rtb = new RichTextBox();

                Button b = new Button();
                b.Text = "Append";
                b.Parent = f;
                b.Click += delegate { rtb.Text += "a"; };
                b.Top = rtb.Height + 10;

                rtb.SelectionChanged += new EventHandler(rtb_SelectionChanged); 
                rtb.TextChanged += delegate { Console.WriteLine("Text

                rtb.Parent = f;

                f.Load +=  delegate { };

                Application.Run (f);

        static void rtb_SelectionChanged(object sender, EventArgs e)
            Console.WriteLine(String.Format("Selection: {0} Length: {1}",
(sender as RichTextBox).SelectionStart,(sender as


If you execute the above program and manually enter 123 into the text box you
should get the following message on the console.

Test #1
Actual Results:

Text Changed
Selection: 1 Length: 0
Text Changed
Selection: 2 Length: 0
Text Changed
Selection: 3 Length: 0

Expected Results:
Selection: 1 Length: 0
Text Changed
Selection: 2 Length: 0
Text Changed
Selection: 3 Length: 0
Text Changed

Test #2
If you use the Append Button
Actual Results:
Selection: 0 Length: 0
Text Changed

Expected Results:
Text Changed

How often does this happen? 
Every Time.

Additional Information:
I have attached a diff which fixes what is described above, not sure about how
a test case can be constructed.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list