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

RadMarkupEditor TextChanged event

2 Answers 45 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
T
Top achievements
Rank 1
T asked on 26 Jun 2015, 06:50 AM

Hi,

I have a RadMarkupEditor on my form and I want to execute some action when the text in the editor is changed. Since this control inherits from System.Windows.Forms.UserControl we can subscribe to the TextChanged event. Unfortunately this event is never fired. Is this normal behavior? Is there any other event I could use to achieve the same?

Thanks,

Tom

2 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 Jun 2015, 12:26 PM
Hello Tom,

Thank you for writing.

Currently, RadMarkupEditor does not provide such notifications, however, with some reflection, we can achieve it. Here is a small sample:
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
 
    RadMarkupDialog dialog = new RadMarkupDialog();
 
    WebBrowser designView = dialog.Editor.GetType().GetField("designView", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dialog.Editor) as WebBrowser;
    designView.DocumentCompleted += delegate
    {
        lastSavedText = designView.Document.Body.InnerHtml;
        designView.Document.Body.KeyUp += Body_KeyUp;
    };
 
    TextBox htmlView = dialog.Editor.GetType().GetField("htmlView", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dialog.Editor) as TextBox;
 
    dialog.ShowDialog();
}
 
void htmlView_TextChanged(object sender, EventArgs e)
{
    //occurs when the text in the Html tab changes
}
string lastSavedText = "";
 
void Body_KeyUp(object sender, HtmlElementEventArgs e)
{
    HtmlElement element = (HtmlElement)sender;
    if (this.lastSavedText != element.Document.Body.InnerHtml)
    {
        //design view is modified
        lastSavedText = element.Document.Body.InnerHtml;
    }
}

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik

0
T
Top achievements
Rank 1
answered on 30 Jun 2015, 10:04 AM

Yes, this worked for me.

Thanks!

Tags
TextBox
Asked by
T
Top achievements
Rank 1
Answers by
Stefan
Telerik team
T
Top achievements
Rank 1
Share this question
or