This is a migrated thread and some comments may be shown as answers.

RadRichTextBox events not as documented

2 Answers 61 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Marcus Eddy
Top achievements
Rank 1
Marcus Eddy asked on 28 Aug 2014, 12:47 AM
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 Answers, 1 is accepted

Sort by
0
Marcus Eddy
Top achievements
Rank 1
answered on 28 Aug 2014, 01:02 AM
I should add that I'm using v. 2014.2.715.40 of the RadControls.
0
George
Telerik team
answered on 01 Sep 2014, 11:33 AM
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.
 
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Marcus Eddy
Top achievements
Rank 1
Answers by
Marcus Eddy
Top achievements
Rank 1
George
Telerik team
Share this question
or