Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Undo and Redo in c#

Undo and Redo in c#

Scheduled Pinned Locked Moved C#
csharphelp
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hiremath71
    wrote on last edited by
    #1

    hi, I am creating a editor in Richtextbox control. and now i want to implement feature Undo and redo .. I am not getting it. pls help me with regards prasad:)

    B J P J S 6 Replies Last reply
    0
    • H hiremath71

      hi, I am creating a editor in Richtextbox control. and now i want to implement feature Undo and redo .. I am not getting it. pls help me with regards prasad:)

      B Offline
      B Offline
      Bekjong
      wrote on last edited by
      #2

      Check out this recent code project article.

      Standards are great! Everybody should have one!

      1 Reply Last reply
      0
      • H hiremath71

        hi, I am creating a editor in Richtextbox control. and now i want to implement feature Undo and redo .. I am not getting it. pls help me with regards prasad:)

        J Offline
        J Offline
        joon vh
        wrote on last edited by
        #3

        Here are some articles: http://www.codeproject.com/useritems/useractionbasedundoredo.asp http://www.codeproject.com/csharp/autoundoredo.asp and this pattern looks promising too: http://en.wikipedia.org/wiki/Memento\_pattern Although they will not be easy to implement with a RichTextBox I think. A simple solution, that comes to my mind would be to save a copy of of the text when a change occurs. Then you can undo by replacing the current one with this copy. You should however limit the number of copies because it will consume a lot of memory when there is a lot of text. Can you show us what you have thought of, or have tried already? Do you have a specific problem, or just no idea where to start? I feel like a twat :p I didn't know RichTextbox has Undo/Redo functionality. Post your code, tell us what the problem is. -- modified at 10:38 Wednesday 21st March, 2007


        Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

        H 1 Reply Last reply
        0
        • H hiremath71

          hi, I am creating a editor in Richtextbox control. and now i want to implement feature Undo and redo .. I am not getting it. pls help me with regards prasad:)

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Before you try to Undo something, you need to check to see whether or not it can be undone. To do this, you need to call CanUndo and only call Undo if it returns true. Similar logic applies to Redo/CanRedo.

          Deja View - the feeling that you've seen this post before.

          H 1 Reply Last reply
          0
          • H hiremath71

            hi, I am creating a editor in Richtextbox control. and now i want to implement feature Undo and redo .. I am not getting it. pls help me with regards prasad:)

            J Offline
            J Offline
            JoeSharp
            wrote on last edited by
            #5

            hi The Richtextbox control have methodes for this issues e.g. Copy(), Paste(), and properties like CanCopy or CanPaste regards

            1 Reply Last reply
            0
            • H hiremath71

              hi, I am creating a editor in Richtextbox control. and now i want to implement feature Undo and redo .. I am not getting it. pls help me with regards prasad:)

              S Offline
              S Offline
              Stefan Troschuetz
              wrote on last edited by
              #6

              Search the articles for "undo" and/or "redo". There are some that cover this topic.


              "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

              www.troschuetz.de

              1 Reply Last reply
              0
              • H hiremath71

                hi, I am creating a editor in Richtextbox control. and now i want to implement feature Undo and redo .. I am not getting it. pls help me with regards prasad:)

                J Offline
                J Offline
                joon vh
                wrote on last edited by
                #7

                I could only find an example in VB. http://www.java2s.com/Code/VB/GUI/RichTextBoxReDoandUnDo.htm this is my own mockup

                private void button1_Click(object sender, EventArgs e)
                {
                    if(richTextBox1.CanUndo)
                    {
                        richTextBox1.Undo();
                    }
                }
                
                // this is just to show the UndoActionName property...
                private void richTextBox1_TextChanged(object sender, EventArgs e)
                {
                    button1.Text = richTextBox1.UndoActionName;
                }
                

                It seems to work fine here.


                Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

                H 1 Reply Last reply
                0
                • J joon vh

                  Here are some articles: http://www.codeproject.com/useritems/useractionbasedundoredo.asp http://www.codeproject.com/csharp/autoundoredo.asp and this pattern looks promising too: http://en.wikipedia.org/wiki/Memento\_pattern Although they will not be easy to implement with a RichTextBox I think. A simple solution, that comes to my mind would be to save a copy of of the text when a change occurs. Then you can undo by replacing the current one with this copy. You should however limit the number of copies because it will consume a lot of memory when there is a lot of text. Can you show us what you have thought of, or have tried already? Do you have a specific problem, or just no idea where to start? I feel like a twat :p I didn't know RichTextbox has Undo/Redo functionality. Post your code, tell us what the problem is. -- modified at 10:38 Wednesday 21st March, 2007


                  Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

                  H Offline
                  H Offline
                  hiremath71
                  wrote on last edited by
                  #8

                  hi, int ActiveUndoIndex = ActiveWindowStatus(); if (arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.CanUndo == true) { arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.Undo(); arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.ClearUndo(); } this code is undoing the enitre actions not chracter by chracter ... help me pls

                  1 Reply Last reply
                  0
                  • P Pete OHanlon

                    Before you try to Undo something, you need to check to see whether or not it can be undone. To do this, you need to call CanUndo and only call Undo if it returns true. Similar logic applies to Redo/CanRedo.

                    Deja View - the feeling that you've seen this post before.

                    H Offline
                    H Offline
                    hiremath71
                    wrote on last edited by
                    #9

                    hi, int ActiveUndoIndex = ActiveWindowStatus(); if (arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.CanUndo == true) { arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.Undo(); arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.ClearUndo(); } this is undoing the entire operation e.g if i enter 100 chracters it is deleting 100 chracters at time for single undo..

                    1 Reply Last reply
                    0
                    • J joon vh

                      I could only find an example in VB. http://www.java2s.com/Code/VB/GUI/RichTextBoxReDoandUnDo.htm this is my own mockup

                      private void button1_Click(object sender, EventArgs e)
                      {
                          if(richTextBox1.CanUndo)
                          {
                              richTextBox1.Undo();
                          }
                      }
                      
                      // this is just to show the UndoActionName property...
                      private void richTextBox1_TextChanged(object sender, EventArgs e)
                      {
                          button1.Text = richTextBox1.UndoActionName;
                      }
                      

                      It seems to work fine here.


                      Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

                      H Offline
                      H Offline
                      hiremath71
                      wrote on last edited by
                      #10

                      hi, int ActiveUndoIndex = ActiveWindowStatus(); if (arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.CanUndo == true) { arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.Undo(); arrScrptDsgnrFrms[ActiveUndoIndex].RchtxtBx.ClearUndo(); } this is undoig all entered characters at single shot e.g if i enter 100 charcters all 100 chractes are removing at a single shot.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups