RadRichTextBox events not as documented

3 posts, 0 answers
  1. Marcus Eddy
    Marcus Eddy avatar
    26 posts
    Member since:
    Jun 2008

    Posted 27 Aug 2014 Link to this post

    I've been having a couple of issues with the RadRichTextBox due to the event handlers not being provided with the parameters they are documented to, particularly with the DocumentContentChanged, DocumentArranged and CurrentEditingStyleChanged events. It probably affects the CurrentParagraphStyleChanged and CurrentSpanStyleChanged events too.
    http://www.telerik.com/help/winforms/richtextbox-events.html
    Both of these events are documented to provide the text box in the sender parameter, but instead they receive the RadDocument and the DocumentView objects, respectively.
     This makes it difficult to share event handlers for different text boxes. I've been able to work around this problem so far by using event handlers specific to each text box on my form (I have several), but is there a way to get the associated text box from either the RadDocument or the DocumentView objects? I have a need to add these event handlers dynamically to dynamically added rich text boxes, and this becomes very problematic if there is no way to get the actual text box from the event handler parameters.
    Is this by design, and it was overlooked in the documentation, or is it a bug? For what it's worth, I could get the RadDocument and DocumentView from the text box if this was provided in the sender parameter.

  2. Marcus Eddy
    Marcus Eddy avatar
    26 posts
    Member since:
    Jun 2008

    Posted 27 Aug 2014 in reply to Marcus Eddy Link to this post

    I should add that I'm using v. 2014.2.715.40 of the RadControls.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. George
    Admin
    George avatar
    500 posts

    Posted 01 Sep 2014 Link to this post

    Hello Marcus,

    Thank you for writing.

    I can confirm that the sender is not correct in these events. Thank you for reporting this. We will update the article to properly reflect the sender in these events. For the meantime you can use an approach which allows you to get the RadRichTextBox from RadDocument:
    private Dictionary<object, RadRichTextBox> map = new Dictionary<object, RadRichTextBox>();
    public Form1()
    {
        richTextBox.HandleCreated += Form1_HandleCreated;
        richTextBox.DocumentArranged += richTextBox_DocumentArranged;
    }
     
    void richTextBox_DocumentArranged(object sender, EventArgs e)
    {
        RadRichTextBox rtb = map[sender];
    }
     
    void Form1_HandleCreated(object sender, EventArgs e)
    {
        RadRichTextBox rtb = sender as RadRichTextBox;
        var doc = rtb.Document;
        map[doc] = rtb;
    }

    This should suffice in your case.

    I have also updated your Telerik Points for reporting this.

    Let me know, should you have other questions.

    Regards,
    George
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top