473,543 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(myRichTextBo x.CanUndo == true)
{
myRichTextBox.U ndo();
}

After typing some text into myRichTextBox, nothing happens when clicking the
button, or using Ctrl+Z... Umm... any idea?
Nov 16 '05 #1
11 15130
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(myRichTextBo x.CanUndo == true)
{
myRichTextBox.U ndo();
}

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(o bject sender, System.EventArg s e) {
base.Text=richT extBox1.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(o bject sender, System.EventArg s
e) { base.Text=richT extBox1.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.CanU ndo == true)
{
//...
CodeBox.Undo();
MessageBox.Show ("Welcome to Undo!"); // :)
}
else
{
Console.WriteLi ne("Thanks for cooperation and have a nice day!");
}
If I place your code... base.Text=Warni ngBox.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.Te xt {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
WindowsApplicat ion form.

public Form1() {
// leave generated code
InitializeCompo nent();

// add those lines
button1.Click+= new EventHandler(bu tton1_Click);
button2.Click+= new EventHandler(bu tton2_Click);
button3.Click+= new EventHandler(bu tton2_Click);
}

private void button1_Click(o bject sender, System.EventArg s e) {
this.DoUndo(ric hTextBox1);
}

private void button2_Click(o bject sender, System.EventArg s e) {
this.DoUndo(ric hTextBox2);
}

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

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

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

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

.... or add just this line:
// ... set and initialize char_x!
y = richTextBox1.Te xt.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
8067
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 submitted, while they are typing, I'm trying to offer them some common word processing functions. I want to implement unlimited undo and redo for the...
3
11615
by: babylon | last post by:
any facilities in csharp that can help me implmenting undo/redo in my application? thx
3
7815
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 samples. Is seems that the 'Command Pattern' is the way to achieve it (?). If you know any good resources I would be very happy to know! Thank...
2
5830
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 effect was reached, I found original undo/redo function didn't work!! Any ideas? Thanks,
2
13257
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 to narrow, since it only can handle 1 object, and since it only works on properties. What if you , in an application, have more than 1 object ,...
0
1376
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; richBox.SelectionLength = token.Length; richBox.SelectionColor = Color.Black; richBox.SelectionFont = regFont;
0
2737
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, as my application demands it. Because for each word in text, I have associated data and so, require to maintain state of associated data also. ...
1
4041
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 commands are not working for me. IMenuCommandService menusrv= HostControl.HostSurface.GetService(typeof(IMenuCommandService)) as...
0
7399
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5258
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3385
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
952
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
626
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.