如何获得RichTextBox中撤消更好的工作? [英] How to get RichTextBox Undo to work better?

查看:296
本文介绍了如何获得RichTextBox中撤消更好的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写使用的RichTextBox 文本编辑器。我关心的是关于撤消和重做可能RichTextBox的功能。

I am trying to write a text editor using RichTextBox. My concern is now about Undo and possibly Redo features of RichTextBox.

当我开始文本框中写,说一分钟!如果我叫撤消方法,它所做的只是我beleive清除或再次重置RichTextBox的。我怎样才能得到它的工作,它可以做的更好,就像撤消最后增加的单词,或最后添加新行......我的意思是你从Undo功能期望平常的事情。 (用于重做同样的罪名也!)

When I start writing in text box, say 1 minute! if I call Undo method, all it does is just I beleive clearing or resetting richtextbox again. How can I get it to work that it can do better, like Undoing last added word, or last added new line...I mean usual things you expect from Undo function. (The same counts for Redo also!)

有属性或一些选项才达到这个?或者我要实现我自己的代码?

Is there properties or some options to achive this? Or I have to implement my own code?

推荐答案

您可以保存介绍最新的数据,当你要撤消你可以改变现在的数据与去年的数据! !介绍最新的数据可以随时设置要

You can save the lastest Data and when you want to undo you can change to now data to last data! lastest data can be set anytime that you want!

我做同一个RichTextBox和一个按钮一个WinForm该按钮撤消写下的文字:

I Make a winForm with a richTextBox and a button that button undo the wrote text:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace test
{


public partial class Form1 : Form
{
    List<string> LastData = new List<string>();

    int undoCount = 0;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        LastData.Add(richTextBox1.Text);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            richTextBox1.Text = LastData[LastData.Count - undoCount - 1];
            ++undoCount;
        }
        catch { }
    }

    private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        LastData.Add(richTextBox1.Text);
        undoCount = 0;
    }
}
}



但我没找到什么更好的和有组织的方式,你可以修改

but I didn't find any better and organized way and you can change

LastData.Add(richTextBox1.Text);
undoCount = 0;

要保存新词或新行

更新:

这篇关于如何获得RichTextBox中撤消更好的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆