RichTextBox.CanUndo()

F

Frank White

I noticed what I thought was peculiar behavior when I used the RichTextBox.
If you get the RTF string from a RichTextBox using the RichTextBox.Rtf
property, the RichTextBox treats this as an action that cannot be undone.
So if you would run the following code as the TextChanged event handler of a
RichTextBox called "rtbox" ....

private void rtbox_TextChanged(object sender, System.EventArgs e) {
Console.WriteLine("CanUndo 1 = " + rtbox.CanUndo);
Console.WriteLine("Rtf = " + rtbox.Rtf);
Console.WriteLine("CanUndo 2 = " + rtbox.CanUndo);
}

..... the following is always the result ....

CanUndo 1 = True
Rtf = [whatever Rtf]
CanUndo 2 = False

This makes no sense to me, and since the Text and TextLength properties of a
RichTextBox also include calls to the Rtf property, obtaining these
properties have the same effect. Initially I thought it was because a call
to the private method StreamOut(int32) is made, which might be considered as
writing to a stream and that might not be undoable. However, the same
method is also called in the SelectedText and SelectedRtf [GET] properties,
but the behavior does not repeat when these properties are used. Can anyone
explain why this happens?

TIA,
kruk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top