RichTextBox için kendi geri alma sistemimi oluşturdum, böylece bir işlemi yaptığınızda geri alma eylemi bir yığına eklenir ve geri aldığınızda, bu işlem geri alınır.RichTextBox Boşlukları Ekleme
Bu davranış, RichTextBoxes dışındakiler için uyguladığım tüm denetimlerle mükemmel çalışır. Sistemi en basit öğelerine indirdim, silme düğmesine bastığınızda geçerli seçili metni ve dizinini bir yığına ekler ve bu işlemi geri aldığınızda metni bu dizine geri koyar. Bir hatta sadece \ n ve bunun gibi aşağıda daha Metni seçmek Ancak
// Struct I use to store undo data
public struct UndoSection
{
public string Undo;
public int Index;
public UndoSection(int index, string undo)
{
Index = index;
Undo = undo;
}
}
public partial class Form1 : Form
{
// Stack for holding Undo Data
Stack<UndoSection> UndoStack = new Stack<UndoSection>();
// If delete is pressed, add a new UndoSection, if ctrl+z is pressed, peform undo.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.None && e.KeyCode == Keys.Delete)
UndoStack.Push(new UndoSection(textBox1.SelectionStart, textBox1.SelectedText));
else if (e.Control && e.KeyCode == Keys.Z)
{
e.Handled = true;
UndoMenuItem_Click(textBox1, new EventArgs());
}
}
// Perform undo by setting selected text at stored index.
private void UndoMenuItem_Click(object sender, EventArgs e)
{
if (UndoStack.Count > 0)
{
// Save last selection for user
int LastStart = textBox1.SelectionStart;
int LastLength = textBox1.SelectionLength;
UndoSection Undo = UndoStack.Pop();
textBox1.Select(Undo.Index, 0);
textBox1.SelectedText = Undo.Undo;
textBox1.Select(LastStart, LastLength);
}
}
}
: Burada
(metin dosyasının asıl okuma gibi) dışarı çıkardı basit unsurlarla kodudur :
Kodu geçtiniz mi? Muhtemelen, yığınınızdaki herşeyi bir yere çıkarmak, sonra yığının yeniden doldurulması? – MunkiPhD