By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,333 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,333 IT Pros & Developers. It's quick & easy.

RichTextBox.CanUndo()

P: n/a
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

------------------
We've learnt that war is not the answer ... except to all of America's
problems.

Bart Simpson

Nov 13 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.