Click here to Skip to main content
15,916,318 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# config file stopped working Pin
Richard Deeming1-Mar-23 3:25
mveRichard Deeming1-Mar-23 3:25 
GeneralRe: C# config file stopped working Pin
Ismael_19992-Mar-23 10:01
Ismael_19992-Mar-23 10:01 
GeneralRe: C# config file stopped working Pin
Richard Deeming2-Mar-23 21:21
mveRichard Deeming2-Mar-23 21:21 
GeneralRe: C# config file stopped working Pin
Eddy Vluggen4-Mar-23 8:03
professionalEddy Vluggen4-Mar-23 8:03 
QuestionNuget Visual Studio Pin
Kevin Dzimiera 202226-Feb-23 11:48
Kevin Dzimiera 202226-Feb-23 11:48 
AnswerRe: Nuget Visual Studio Pin
Dave Kreskowiak26-Feb-23 15:20
mveDave Kreskowiak26-Feb-23 15:20 
AnswerRe: Nuget Visual Studio Pin
Eddy Vluggen4-Mar-23 8:07
professionalEddy Vluggen4-Mar-23 8:07 
QuestionDeleting characters from a list<char> Pin
mjcs10024-Feb-23 5:53
mjcs10024-Feb-23 5:53 
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<char>'. 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<char> 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(menuRedoEdit.Font, FontStyle.Regular);
                //sets the color to black...
                menuRedoEdit.ForeColor = Color.Black;
                //sets the button text to redo
                menuRedoEdit.Text = "Redo";
            }
            menuUndoEditClicked = false;
        }


private void menuRedoEdit_Click(object sender, EventArgs e)
        {
            menuRedoEditClicked = true;

            UndoRedo.redo();
            
            if (UndoRedo.charList.Count == 0)
            {
                menuRedoEdit.Enabled = false;
                menuRedoEdit.Font = new Font(menuRedoEdit.Font, FontStyle.Italic);
                menuRedoEdit.ForeColor = Color.DarkGray;
                menuRedoEdit.Text = "Can't Redo";
            }

            menuRedoEditClicked = false;

            richTxtDirections.Focus();
        }


private void richTxtDirections_KeyDown(object sender, KeyEventArgs e)
        {
            //adding a character count to show the user how many was put in and that they can only go to what is max.
            lblCount2.Text = richTxtDirections.Text.Length + "/750";

            //condition to see if rich textbox directions is empty or not
            if (richTxtDirections.Focused == true && richTxtDirections.Text != string.Empty)
            {
                if (menuUndoEdit.Enabled == false)
                {
                    //when there is a change in the textbox, undo button is enabled
                    menuUndoEdit.Enabled = true;

                    //changes the font to regular and whatever font specified
                    menuUndoEdit.Font = new Font(menuUndoEdit.Font, FontStyle.Regular);

                    //changes the font color to normal
                    menuUndoEdit.ForeColor = Color.Black;
                }

                //condition where rich textbox is not empty and checks to see if 'z' key was pressed.
                if (e.KeyCode == Keys.Z && (e.Control))
                {
                    e.Handled = true;

                    menuUndoEdit.PerformClick();
                }

                //condition where rich textbox is not empty and checks to see if 'y' key was pressed.
                else if (e.KeyCode == Keys.Y && e.Control)
                {
                    e.Handled = true;

                    menuRedoEdit.PerformClick();
                }
            }
        }

        private void richTxtDirections_TextChanged(object sender, EventArgs e)
        {
            if (UndoRedo.charList.Count > 0 && menuRedoEditClicked == false)
            {
                UndoRedo.clearList();
            }
        }


public void undo()
        {
            //condition to see if rich textbox directions has text in it.
            if (frmDashboard.instance.tbrdDirections.Text.Length > 0)
            {
                //adding the characters in the string that is in the textbox text to the list
                charList.Add(frmDashboard.instance.tbrdDirections.Text[frmDashboard.instance.tbrdDirections.Text.Length - 1]);
            }
        }

        public void redo()
        {
            //condition to see if the list has anything stored in it
            if (charList.Count > 0)
            {
                //creating a variable to store the list
                var lastItem = charList.Last();

                //appending the characters to the end of directions textbox text
                frmDashboard.instance.tbrdDirections.AppendText(lastItem.ToString());

                //removing the character from the list
                charList.RemoveAt(charList.Count - 1);
            }
        }

        public void clearList()
        {
            //condition to see if the list has anything stored in it
            if (charList.Count > 0)
            {
                //if the list has stored unused items left in it, it clears the list.
                charList.Clear();

                //since there is nothing to redo on the form, it disables the redo button
                frmDashboard.instance.mnuRedoEdit.Enabled = false;
            }
        }

AnswerRe: Deleting characters from a list<char> Pin
Gerry Schmitz24-Feb-23 8:53
mveGerry Schmitz24-Feb-23 8:53 
GeneralRe: Deleting characters from a list<char> Pin
mjcs10024-Feb-23 11:18
mjcs10024-Feb-23 11:18 
GeneralRe: Deleting characters from a list<char> Pin
Gerry Schmitz24-Feb-23 19:25
mveGerry Schmitz24-Feb-23 19:25 
GeneralRe: Deleting characters from a list<char> Pin
mjcs10024-Feb-23 20:35
mjcs10024-Feb-23 20:35 
GeneralRe: Deleting characters from a list<char> Pin
Gerry Schmitz25-Feb-23 6:39
mveGerry Schmitz25-Feb-23 6:39 
AnswerRe: Deleting characters from a list<char> Pin
Eddy Vluggen25-Feb-23 6:24
professionalEddy Vluggen25-Feb-23 6:24 
AnswerRe: Deleting characters from a list<char> Pin
lmoelleb27-Feb-23 4:45
lmoelleb27-Feb-23 4:45 
AnswerRe: Deleting characters from a list<char> Pin
jochance7-Mar-23 8:21
jochance7-Mar-23 8:21 
QuestionC# xml serialization Pin
di24125313416-Feb-23 2:02
di24125313416-Feb-23 2:02 
AnswerRe: C# xml serialization Pin
Richard Deeming16-Feb-23 2:17
mveRichard Deeming16-Feb-23 2:17 
AnswerRe: C# xml serialization Pin
Dave Kreskowiak16-Feb-23 2:28
mveDave Kreskowiak16-Feb-23 2:28 
AnswerRe: C# xml serialization Pin
OriginalGriff16-Feb-23 9:00
mveOriginalGriff16-Feb-23 9:00 
QuestionSQL Injection Detection Pin
Member 805432115-Feb-23 5:01
Member 805432115-Feb-23 5:01 
AnswerRe: SQL Injection Detection Pin
OriginalGriff15-Feb-23 5:21
mveOriginalGriff15-Feb-23 5:21 
Question.NetMAUI and NAudio Pin
D^Handy14-Feb-23 17:47
D^Handy14-Feb-23 17:47 
AnswerRe: .NetMAUI and NAudio Pin
Gerry Schmitz15-Feb-23 12:35
mveGerry Schmitz15-Feb-23 12:35 
GeneralRe: .NetMAUI and NAudio Pin
D^Handy15-Feb-23 12:40
D^Handy15-Feb-23 12:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.