Deleting characters from a list<char>
-
I have a program I am working on. First I will explain what I have done and then get to the question. I have created a undo and redo functions that when undo, it deletes one character at a time from the string and puts it in a 'List'. Then when you click redo, it goes to the 'List' and adds each character back to the string and deletes it from the list, one character at a time. You can see in the pictures the undo and redo menu button click events for them in the 1st pic. They get their functions from the 2nd pic., the undo redo class. I also have a keydown and text change function shown in pic. 3. All functions work good but the clearing of the 'list' that remains if they don't 'redo' all commands. I can undo and redo and have no problems, but I want it to delete the list contents after the user starts to type again after undoing and redoing. I have tried to put it in the text change but it keeps firing every time the list is over '0' and after the menu redo is enabled. I have tried putting in the buttons function, and I even tried to do the stack process, but I could not get my head wrapped around that option. I know that 'richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1);' deletes 1 character, but how do you say if the 'text.length +1' from where you stop to undo and redo, how to add a character. I hope I am explaining this fine for you to understand and that someone can possibly help me with this part, even if it is not adding 1 to the text.length. Thank you.
private void menuUndoEdit_Click(object sender, EventArgs e)
{
menuUndoEditClicked = true;//accesses the undo function to undo last command UndoRedo.undo(); if (richTxtDirections.Text.Length > 0) { //removes the last character in the text in the textbox richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1); //positions the cursor at the end of the text richTxtDirections.Select(richTxtDirections.Text.Length, 0); } //condition for menu redo edit button is enabled if (menuRedoEdit.Enabled == false) { //if the keys (control and Z) are pressed enables the redo button... menuRedoEdit.Enabled = true; //sets the font to specified font and style to regular.... menuRedoEdit.Font = new Font(menu
-
I have a program I am working on. First I will explain what I have done and then get to the question. I have created a undo and redo functions that when undo, it deletes one character at a time from the string and puts it in a 'List'. Then when you click redo, it goes to the 'List' and adds each character back to the string and deletes it from the list, one character at a time. You can see in the pictures the undo and redo menu button click events for them in the 1st pic. They get their functions from the 2nd pic., the undo redo class. I also have a keydown and text change function shown in pic. 3. All functions work good but the clearing of the 'list' that remains if they don't 'redo' all commands. I can undo and redo and have no problems, but I want it to delete the list contents after the user starts to type again after undoing and redoing. I have tried to put it in the text change but it keeps firing every time the list is over '0' and after the menu redo is enabled. I have tried putting in the buttons function, and I even tried to do the stack process, but I could not get my head wrapped around that option. I know that 'richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1);' deletes 1 character, but how do you say if the 'text.length +1' from where you stop to undo and redo, how to add a character. I hope I am explaining this fine for you to understand and that someone can possibly help me with this part, even if it is not adding 1 to the text.length. Thank you.
private void menuUndoEdit_Click(object sender, EventArgs e)
{
menuUndoEditClicked = true;//accesses the undo function to undo last command UndoRedo.undo(); if (richTxtDirections.Text.Length > 0) { //removes the last character in the text in the textbox richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1); //positions the cursor at the end of the text richTxtDirections.Select(richTxtDirections.Text.Length, 0); } //condition for menu redo edit button is enabled if (menuRedoEdit.Enabled == false) { //if the keys (control and Z) are pressed enables the redo button... menuRedoEdit.Enabled = true; //sets the font to specified font and style to regular.... menuRedoEdit.Font = new Font(menu
If you want to clear the list when someone "types", why do you have extra conditions in the text changed event?
if (UndoRedo.charList.Count > 0 && menuRedoEditClicked == false)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
If you want to clear the list when someone "types", why do you have extra conditions in the text changed event?
if (UndoRedo.charList.Count > 0 && menuRedoEditClicked == false)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
Because I don't want it to clear it every time the text changes or keydown event fires but just after the user starts to type and quit. So I tried to put an extra condition to help stop it but its not. I hope I am explaining myself right.
I think you need to better explain what "type and quit" means. And you're talking as if "text changes" and "key down" are somehow independent. Maybe you should be looking at individual key presses in the preview key down event.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I think you need to better explain what "type and quit" means. And you're talking as if "text changes" and "key down" are somehow independent. Maybe you should be looking at individual key presses in the preview key down event.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
I'm sorry Gerry. I wondered if I explained it wrong. Let me try this again. I was looking for help on how to delete the list after the user is finished 'undo' commands or 'redo' commands, and the user starts typing on the keyboard, in the rich textbox, the rest of the directions for a recipe. I have used the the 'keydown' function to add the command that if a key was pressed, to delete the list if its greater than 0, but it deletes the list every time the user clicks the 'ctrl' and 'z' shortcut. I don't want it to empty the new characters added to the list by the 'undo' function, because there would be nothing left if he needs to 'redo' one or two. I was thinking if there was a text change, something like typing then stop to 'undo' and start typing again, that it may work, but it does not. Still deletes each character. I'm not even sure if that would be considered text change also. So now I am at a point I am asking if someone knows what how. I'm am fairly new at programming and have learned everything about it myself and doing it all myself. I know I explain things wrong or have the wrong terms for whatever, and I'm sorry if I did not explain better. My hubby always tells me I cant explain things the way they should be.
-
I have a program I am working on. First I will explain what I have done and then get to the question. I have created a undo and redo functions that when undo, it deletes one character at a time from the string and puts it in a 'List'. Then when you click redo, it goes to the 'List' and adds each character back to the string and deletes it from the list, one character at a time. You can see in the pictures the undo and redo menu button click events for them in the 1st pic. They get their functions from the 2nd pic., the undo redo class. I also have a keydown and text change function shown in pic. 3. All functions work good but the clearing of the 'list' that remains if they don't 'redo' all commands. I can undo and redo and have no problems, but I want it to delete the list contents after the user starts to type again after undoing and redoing. I have tried to put it in the text change but it keeps firing every time the list is over '0' and after the menu redo is enabled. I have tried putting in the buttons function, and I even tried to do the stack process, but I could not get my head wrapped around that option. I know that 'richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1);' deletes 1 character, but how do you say if the 'text.length +1' from where you stop to undo and redo, how to add a character. I hope I am explaining this fine for you to understand and that someone can possibly help me with this part, even if it is not adding 1 to the text.length. Thank you.
private void menuUndoEdit_Click(object sender, EventArgs e)
{
menuUndoEditClicked = true;//accesses the undo function to undo last command UndoRedo.undo(); if (richTxtDirections.Text.Length > 0) { //removes the last character in the text in the textbox richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1); //positions the cursor at the end of the text richTxtDirections.Select(richTxtDirections.Text.Length, 0); } //condition for menu redo edit button is enabled if (menuRedoEdit.Enabled == false) { //if the keys (control and Z) are pressed enables the redo button... menuRedoEdit.Enabled = true; //sets the font to specified font and style to regular.... menuRedoEdit.Font = new Font(menu
mjcs100 wrote:
I have created a undo and redo functions that when undo, it deletes one character at a time from the string and puts it in a 'List<char>'
Yah, that changes a char, but doesn't do/undo the last action. You want a memento-pattern. It's easier, cleaner, and better, because it also can do/undo any font-changes.
Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
I'm sorry Gerry. I wondered if I explained it wrong. Let me try this again. I was looking for help on how to delete the list after the user is finished 'undo' commands or 'redo' commands, and the user starts typing on the keyboard, in the rich textbox, the rest of the directions for a recipe. I have used the the 'keydown' function to add the command that if a key was pressed, to delete the list if its greater than 0, but it deletes the list every time the user clicks the 'ctrl' and 'z' shortcut. I don't want it to empty the new characters added to the list by the 'undo' function, because there would be nothing left if he needs to 'redo' one or two. I was thinking if there was a text change, something like typing then stop to 'undo' and start typing again, that it may work, but it does not. Still deletes each character. I'm not even sure if that would be considered text change also. So now I am at a point I am asking if someone knows what how. I'm am fairly new at programming and have learned everything about it myself and doing it all myself. I know I explain things wrong or have the wrong terms for whatever, and I'm sorry if I did not explain better. My hubby always tells me I cant explain things the way they should be.
Your "key down" goes off and does something in "PerformClick()". I'd look there.
menuUndoEdit.PerformClick();
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I have a program I am working on. First I will explain what I have done and then get to the question. I have created a undo and redo functions that when undo, it deletes one character at a time from the string and puts it in a 'List'. Then when you click redo, it goes to the 'List' and adds each character back to the string and deletes it from the list, one character at a time. You can see in the pictures the undo and redo menu button click events for them in the 1st pic. They get their functions from the 2nd pic., the undo redo class. I also have a keydown and text change function shown in pic. 3. All functions work good but the clearing of the 'list' that remains if they don't 'redo' all commands. I can undo and redo and have no problems, but I want it to delete the list contents after the user starts to type again after undoing and redoing. I have tried to put it in the text change but it keeps firing every time the list is over '0' and after the menu redo is enabled. I have tried putting in the buttons function, and I even tried to do the stack process, but I could not get my head wrapped around that option. I know that 'richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1);' deletes 1 character, but how do you say if the 'text.length +1' from where you stop to undo and redo, how to add a character. I hope I am explaining this fine for you to understand and that someone can possibly help me with this part, even if it is not adding 1 to the text.length. Thank you.
private void menuUndoEdit_Click(object sender, EventArgs e)
{
menuUndoEditClicked = true;//accesses the undo function to undo last command UndoRedo.undo(); if (richTxtDirections.Text.Length > 0) { //removes the last character in the text in the textbox richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1); //positions the cursor at the end of the text richTxtDirections.Select(richTxtDirections.Text.Length, 0); } //condition for menu redo edit button is enabled if (menuRedoEdit.Enabled == false) { //if the keys (control and Z) are pressed enables the redo button... menuRedoEdit.Enabled = true; //sets the font to specified font and style to regular.... menuRedoEdit.Font = new Font(menu
I am not sure what controls you are using, but have you checked undo/redo is not already supported by the control - I would expect it is. For example: Windows Forms Redo[^] WPF Redo[^] Your implementation is very limited. As already mentioned you do not handle formatting - but you also assume the last character is the last one entered.
-
I have a program I am working on. First I will explain what I have done and then get to the question. I have created a undo and redo functions that when undo, it deletes one character at a time from the string and puts it in a 'List'. Then when you click redo, it goes to the 'List' and adds each character back to the string and deletes it from the list, one character at a time. You can see in the pictures the undo and redo menu button click events for them in the 1st pic. They get their functions from the 2nd pic., the undo redo class. I also have a keydown and text change function shown in pic. 3. All functions work good but the clearing of the 'list' that remains if they don't 'redo' all commands. I can undo and redo and have no problems, but I want it to delete the list contents after the user starts to type again after undoing and redoing. I have tried to put it in the text change but it keeps firing every time the list is over '0' and after the menu redo is enabled. I have tried putting in the buttons function, and I even tried to do the stack process, but I could not get my head wrapped around that option. I know that 'richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1);' deletes 1 character, but how do you say if the 'text.length +1' from where you stop to undo and redo, how to add a character. I hope I am explaining this fine for you to understand and that someone can possibly help me with this part, even if it is not adding 1 to the text.length. Thank you.
private void menuUndoEdit_Click(object sender, EventArgs e)
{
menuUndoEditClicked = true;//accesses the undo function to undo last command UndoRedo.undo(); if (richTxtDirections.Text.Length > 0) { //removes the last character in the text in the textbox richTxtDirections.Text = richTxtDirections.Text.Remove(richTxtDirections.Text.Length - 1); //positions the cursor at the end of the text richTxtDirections.Select(richTxtDirections.Text.Length, 0); } //condition for menu redo edit button is enabled if (menuRedoEdit.Enabled == false) { //if the keys (control and Z) are pressed enables the redo button... menuRedoEdit.Enabled = true; //sets the font to specified font and style to regular.... menuRedoEdit.Font = new Font(menu
You might consider using Stack versus List for charList. It has Push() (add to list), Peek() (look at the "topmost" list member), and Pop() (retrieve value and remove the topmost list member). It is just the sort of LIFO collection it sounds like you may want.