473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 15104
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lkrubner | last post by:
I'm offering users the ability to type weblog posts into a form and post them. They type the text into a TEXTAREA which is on a form. The form, when submitted, hits a PHP script. Before it is...
3
by: babylon | last post by:
any facilities in csharp that can help me implmenting undo/redo in my application? thx
3
by: Teis Draiby | last post by:
I'm looking for some information (books, articles, tutorials) on how to implement a multiple undo/redo framework. I'm a beginner in this so I prefer information specifically targeting C# with code...
2
by: Alan | last post by:
Hi all, I want to hilight some syntax keywords. While parsing text, I used these properties such as SelectionStart,SelectionLength and SelectionColor of RichTextBox. Although the syntaxhilghting...
2
by: Christian H | last post by:
Hello, I've tried to find information about how to implement an Undo/Redo pattern. This article describes such a pattern: http://www.codeproject.com/csharp/PcObjectUndo.asp , but is a little bit...
0
by: nuwankkumara | last post by:
hai all, i am using RichTextBox as my editor , there i can't perform undo and redo when i have changed the color and font of the text as below: richBox.SelectionStart = index;...
0
by: Sakharam Phapale | last post by:
Hi All, I am developing my own text editor using RichTextBox control. I don't want to use RichTextBox Undo and Redo functions. Instead of that I want to develop my own algorithm for Undo & Redo,...
1
by: anupam roy | last post by:
Hi All, I want to perform basic Edit menu functionalities on my custom design surface. While all the Cut/Copy/Paste/Deelete/Select functionalities working fine with code below,Undo/Redo standard...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.