469,267 Members | 1,643 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

richTextBox UNDO/REDO

I'm using a richTextBox for editing a source code (with Syntax Highlighting)
of my own programming language...
How come that myRichTextBox doesn't respond to Undo/Redo functions by using
default shortcut keys, or even programaticaly (by using Button_onClick
event)?

if(myRichTextBox.CanUndo == true)
{
myRichTextBox.Undo();
}

After typing some text into myRichTextBox, nothing happens when clicking the
button, or using Ctrl+Z... Umm... any idea?
Nov 16 '05 #1
11 14457
Hi Joe,
I'm using a richTextBox for editing a source code (with Syntax Highlighting)
of my own programming language...
How come that myRichTextBox doesn't respond to Undo/Redo functions by using
default shortcut keys, or even programaticaly (by using Button_onClick
event)?

if(myRichTextBox.CanUndo == true)
{
myRichTextBox.Undo();
}

After typing some text into myRichTextBox, nothing happens when clicking the
button, or using Ctrl+Z... Umm... any idea?


Are You sure You have KeyDown or MenuItem_Click event handled?

If You've got menu and menuitem "edit/undo" then that menuitem's
shortcut should be set to "Ctrl-Z".
I didn't have any problem with undo and button combination.

Regards

Marcin
Nov 16 '05 #2
Marcin Grzębski wrote:
Are You sure You have KeyDown or MenuItem_Click event handled?
If You've got menu and menuitem "edit/undo" then that menuitem's
shortcut should be set to "Ctrl-Z"...


Yo, Marcin! ;)
I don't have problems either with all of my other richTextBox, just this
one... I double checked and debugged the code, so I'm pretty sure that I
have set a good event. I'm pretty confused also! One more thing: you don't
have to set a shortcut for your menuItemUndo to get this work - just by
pressing the default shortcut keys (Ctrl+Z) you'll reach the Undo feature by
default from Windows (I guess), but that's NOT working for my RTB and I
don't know why?
Nov 16 '05 #3
Hi Joe,
Marcin Grzębski wrote:
Are You sure You have KeyDown or MenuItem_Click event handled?
If You've got menu and menuitem "edit/undo" then that menuitem's
shortcut should be set to "Ctrl-Z"...

Yo, Marcin! ;)
I don't have problems either with all of my other richTextBox, just this
one... I double checked and debugged the code, so I'm pretty sure that I
have set a good event. I'm pretty confused also! One more thing: you don't
have to set a shortcut for your menuItemUndo to get this work - just by
pressing the default shortcut keys (Ctrl+Z) you'll reach the Undo feature by
default from Windows (I guess), but that's NOT working for my RTB and I
don't know why?


So, it looks very strange to me too!

"Ctrl+Z" combination was working fine on RichTextBox control ;)
.... till i have set "Ctrl+Z" shortcut on single MainMenu's menuitem
Check if You have any menuitem's shortcut set to "Ctrl+Z"

This is standard RichTextBox .NET control or it's an inherited
control or totaly new control?

Marcin
Nov 16 '05 #4
Hey Joe,

It looks as a bug in RichTextBox...

private void button1_Click(object sender, System.EventArgs e) {
base.Text=richTextBox1.Text;
// here's no Undo possible
}

If "Text" will be get from RichTextBox, that control
lose UNDO possibility.

Cheers!

Marcin

Nov 16 '05 #5
Marcin Grzębski wrote:
"Ctrl+Z" combination was working fine on RichTextBox control ;)
... till i have set "Ctrl+Z" shortcut on single MainMenu's menuitem
Check if You have any menuitem's shortcut set to "Ctrl+Z"
Double checked too... I don't have any of those shortcuts set to Ctrl+Z.
This is standard RichTextBox .NET control or it's an inherited
control or totaly new control?


Very standard, regular .NET, 100% pure RichTextBox, low fat, sugar free! ;)
Nov 16 '05 #6
Marcin Grzębski wrote:
It looks as a bug in RichTextBox...
private void button1_Click(object sender, System.EventArgs
e) { base.Text=richTextBox1.Text;
// here's no Undo possible
}
Ok, now we're heading somewhere... ;)

In fact I have TWO richTextBoxes in my form:
1.) to edit the source code (let's call it: Code Box)
2.) to inform the user about warnings, errors etc. (Warning Box)

There is also a button with an onClick event designed just for one "Box":
if(CodeBox.CanUndo == true)
{
//...
CodeBox.Undo();
MessageBox.Show("Welcome to Undo!"); // :)
}
else
{
Console.WriteLine("Thanks for cooperation and have a nice day!");
}
If I place your code... base.Text=WarningBox.Text; .... and the content of the Box was "AAA" at that point, I'll still be able
to undo some NEW added text (by typing it manualy) in Warning Box until the
content returns back to "AAA" again.

But anyway, if I do the same thing with my upper Box (The Code Box), I won't
be able to Undo anything and the MessageBox from that "IF-clause" never
shows up. Everything I can get is that line in my Output Window wishing me a
nice day! :o)

Let's say that I don't have menuItems at all and no shortcuts as well.
If I set ReadOnly to "false" to both components, then I'm able to use Ctrl+Z
as "Undo feature" only in my Warning Box, but NOT in my Code Box! The only
difference between those two boxes is that there are lots of parsing
elements in my Code Box for Syntax HighLighting.
I'll try to debug it more carefully and let you know if I solved the
mystery.
If "Text" will be get from RichTextBox, that control
lose UNDO possibility.


I agree that this could be a bug whatsoever... Thanks for your help, Marcin!
Nov 16 '05 #7
Hi again!
Let's say that I don't have menuItems at all and no shortcuts as well.
If I set ReadOnly to "false" to both components, then I'm able to use Ctrl+Z
as "Undo feature" only in my Warning Box, but NOT in my Code Box! The only
difference between those two boxes is that there are lots of parsing
elements in my Code Box for Syntax HighLighting.


Your parsing does not use "RichTextBox.Text {get; }" ?
If "Text" will be get from RichTextBox, that control
lose UNDO possibility.

I agree that this could be a bug whatsoever... Thanks for your help, Marcin!


If this UNDO problem doesn't solve i can propose You to write
your own UNDO/REDO component, with extended functionality
(e.g. unlimitet/limitet count of undo/redo levels).

Marcin

--------------------------------------
try this code: two RichTextBoxes and three buttons on a new
WindowsApplication form.

public Form1() {
// leave generated code
InitializeComponent();

// add those lines
button1.Click+=new EventHandler(button1_Click);
button2.Click+=new EventHandler(button2_Click);
button3.Click+=new EventHandler(button2_Click);
}

private void button1_Click(object sender, System.EventArgs e) {
this.DoUndo(richTextBox1);
}

private void button2_Click(object sender, System.EventArgs e) {
this.DoUndo(richTextBox2);
}

private void DoUndo(RichTextBox richTxtBox) {
if( richTxtBox.CanUndo ) {
richTxtBox.Undo();
}
else {
MessageBox.Show(this
, "There's no undo on: " + richTxtBox.Name);
}
}

private void button3_Click(object sender, System.EventArgs e) {
MessageBox.Show(this
, String.Format("{0}||||{1}"
, richTextBox1.Text
, richTextBox2.Text));
}
Nov 16 '05 #8
Marcin Grzębski wrote:
Your parsing does not use "RichTextBox.Text {get; }" ?
I use lots of RegEx-es onSelectionChange event, with taking substrings of my
richBoxText into variables and THERE is the problem!

Try to myke your own function for "SelectionChanged_Click" with this
content:

// add this...
if (richTextBox1.Text.Length > max)
{
MessageBox.Show("Line feed exceeded!");
}

.... or add just this line:
// ... set and initialize char_x!
y = richTextBox1.Text.Substring(0, char_x);
You were right! I think we just found a real bug! Damn it!
If this UNDO problem doesn't solve i can propose You to write
your own UNDO/REDO component, with extended functionality
(e.g. unlimitet/limitet count of undo/redo levels).


I would appreciate that very much indeed! Thanks again Marcin and well done,
Poland! :)

Joe
Nov 16 '05 #9
Hi,

You were right! I think we just found a real bug! Damn it!

Yeah, Damn...
I hope that Whidbey release solves that problem and problems with
other .NET controls.
I think that MS has a lot of work to do with new .NET.

In my work, we decided to stay with VS/framework 2002, because
VS/framework 2003 had so small count of bugs fixed.
I would appreciate that very much indeed! Thanks again Marcin and well done,
Poland! :)

:)

Joe, Are You from Croatia?

Marcin
Nov 16 '05 #10
Marcin Grzębski wrote:
I hope that Whidbey release solves that problem and problems with
other .NET controls.
Is it possible to use some kind of patch or installation just to fix this
bug? I just downloaded this file (Visual C# "Whidbey": Language
Enhancements):
http://www.hands-on-labs.com/only4gu...pdc/TLS320.zip (375Kb)
I think that MS has a lot of work to do with new .NET.
In my work, we decided to stay with VS/framework 2002, because
VS/framework 2003 had so small count of bugs fixed.
I also use VS .NET 2002...
Joe, Are You from Croatia?


Yes, I was born and raised in Zagreb, Croatia! Catch you later, dude! :)
Nov 16 '05 #11
Hi
Is it possible to use some kind of patch or installation just to fix this
bug? I just downloaded this file (Visual C# "Whidbey": Language
Enhancements):
http://www.hands-on-labs.com/only4gu...pdc/TLS320.zip (375Kb)
Thanx for link!
I have read about most of whidbey features, but this slides are
much more concrete.
Yes, I was born and raised in Zagreb, Croatia! Catch you later, dude! :)


Big Greetings for Croatia
from Poland :)

Marcin

PS: CROTEAM is well known here. Serious!! ;)
Nov 16 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Teis Draiby | last post: by
2 posts views Thread by Christian H | last post: by
reply views Thread by nuwankkumara | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.