undo function - programming methods

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Does anyone have information regarding programming methods
used to include 'UNDO' functionality into a simple editor?
 
Both the textbox and richtextbox have an "Undo" method which can be called
directly. Do you need something really advanced or will this do it for you?

I've written something that can go back to a specific point back instead of
just undoing it, but it's a lot of code and not very elegant. However, if
you need somethign like that let me know and I'll send you what I have.

Bill
 
Bill,

that will do the job - I hadn't realised undo was
available as a function of the control. I appreciate the
tip.
 
If you aren't looking for multiple levels of undo, you can take
advantage of the built-in undo handling that many controls already catch,
with the WM_UNDO message. I wrote this in VB.NET but I'll convert a couple
of lines to C# for you (untested!):

First, import sendmessage:

[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern uint SendMessage(IntPtr hWnd, uint wMsg,
uint wParam, uint lParam);

Also, declare:
public const int WM_UNDO = 0x304;

Then, test this anywhere in your windows forms code:

SendMessage(this.ActiveControl.Handle, WM_UNDO, 0, 0)

A bit of a hack, but it gets the job done if you want something
simple!

Erik
 
Steve,
"Design Patterns - Elements of Reusable Object-Oriented Software" by the GOF
(Gang of Four) Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides from
Addison Wesley Professional Computing Series has a discussion on Undo & Redo
based on the Command Pattern.

Hope this helps
Jay
 
Erik:

Thanks for the tip. I've built something on the fly using a stack, but was
yucky. I've been looking for something a bit more elegant and this is it.

Thanks,

Bill
Erik Frey said:
If you aren't looking for multiple levels of undo, you can take
advantage of the built-in undo handling that many controls already catch,
with the WM_UNDO message. I wrote this in VB.NET but I'll convert a couple
of lines to C# for you (untested!):

First, import sendmessage:

[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern uint SendMessage(IntPtr hWnd, uint wMsg,
uint wParam, uint lParam);

Also, declare:
public const int WM_UNDO = 0x304;

Then, test this anywhere in your windows forms code:

SendMessage(this.ActiveControl.Handle, WM_UNDO, 0, 0)

A bit of a hack, but it gets the job done if you want something
simple!

Erik

Steve said:
Does anyone have information regarding programming methods
used to include 'UNDO' functionality into a simple editor?
 
Well, I have asked enough questions on this NG that it's nice to have an
answer, for once :)

Glad it helped.
 
Back
Top