private void NoteTitleTB_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!string.IsNullOrEmpty(NoteTitleTB.Text) && !string.IsNullOrWhiteSpace(NoteTitleTB.Text))
                {
                    if (NoteTitleTB.Text != Current_Note.Name)
                    {
                        if (!Duplicate_Note(NoteTitleTB.Text))
                        {
                            NotesLV.Sorting = SortOrder.None;

                            Note_Changes.Remove(Current_Note.Name);
                            Note_Changes.Add(NoteTitleTB.Text, NoteBodyTB.Text);

                            Current_Note.Name = NoteTitleTB.Text;
                            Current_Note.Text = NoteTitleTB.Text;

                            NotesLV.Sorting = SortOrder.Ascending;
                            NotesLV.Sort();
                        }

                        else
                        {
                            MessageBox.Show("Duplicate note titles are not allowed.", "Duplicate Note Title", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            NoteTitleTB.Text = Current_Note.Name;
                            NoteTitleTB.Focus();
                            NoteTitleTB.SelectAll();
                        }
                    }
                }

                e.SuppressKeyPress = true;
            }
        }
        private void AddNoteBT_Click(object sender, EventArgs e)
        {
            ListViewItem temp = new ListViewItem()
            {
                Name = "blanknote",
                Text = "blanknote"
            };

            if (Duplicate_Note("blanknote"))
            {
                MessageBox.Show("A blank note already exists, please edit this note before adding another.", "Duplicate Blank Note", MessageBoxButtons.OK, MessageBoxIcon.Error);
                NotesLV.SelectedItems.Clear();
                NotesLV.Items[Get_Blank_Note_Index()].Selected = true;
                NotesLV.Select();
                NoteTitleTB.Focus();
                DeleteNoteBT.Visible = true;
            }

            else
            {
                NotesLV.Sorting = SortOrder.None;
                NotesLV.Items.Insert(0, temp);
                NotesLV.SelectedItems.Clear();
                NotesLV.Items[0].Selected = true;
                NotesLV.Select();
                NoteTitleTB.Focus();

                if (NotesLV.Items.Count == 1)
                {
                    Current_Note        = NotesLV.SelectedItems[0];
                    Current_Note.Font   = BoldFont;
                    NoteTitleTB.Enabled = true;
                    NoteBodyTB.Enabled  = true;

                    NoteTitleTB.Text = Current_Note.Name;
                    NoteBodyTB.Text  = string.Empty;
                    NotesLV.Select();
                    DeleteNoteBT.Visible = true;
                }
            }
        }
 private void NoteTitleTB_Click(object sender, EventArgs e)
 {
     NoteTitleTB.SelectAll();
 }
        private void DeleteNoteBT_Click(object sender, EventArgs e)
        {
            if (Current_Note != null)
            {
                DialogResult delete;

                delete = MessageBox.Show("Are you sure you want to delete \"" + Current_Note.Name + "\"?", "Delete Note", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (delete == DialogResult.Yes)
                {
                    Deleting_Item = true;
                    Note_Changes.Remove(Current_Note.Name);
                    NotesLV.Items.Remove(Current_Note);
                    Deleting_Item = false;

                    NotesLV.SelectedItems.Clear();

                    try
                    {
                        NotesLV.Items[0].Selected = true;
                    }

                    catch
                    {
                    }

                    NotesLV.Select();

                    try
                    {
                        Current_Note = NotesLV.SelectedItems[0];
                    }

                    catch
                    {
                        Current_Note = null;
                        NoteTitleTB.Clear();
                        NoteBodyTB.Clear();
                        NoteTitleTB.Enabled = false;
                        NoteBodyTB.Enabled  = false;
                    }

                    Previous_Note = null;

                    try
                    {
                        Current_Note.Font = BoldFont;
                        NoteTitleTB.Text  = Current_Note.Name;
                    }

                    catch
                    {
                    }

                    try
                    {
                        NoteBodyTB.Text = Note_Changes[Current_Note.Name];
                    }

                    catch
                    {
                    }
                }
            }

            if (NotesLV.Items.Count == 0)
            {
                DeleteNoteBT.Visible = false;
            }
        }
        private void Selection_Changed_Selection_Changed_EventHandler(object sender, EventArgs e)
        {
            if (Selection_Changed.Selection_Changed)
            {
                if (_lock)
                {
                }

                else if (!_lock)
                {
                    _lock = true;

                    // Going from selected to deselected
                    // Happens when selecting another item after an already selected one or selecting nothing after a selected item
                    if (Current_Count == 0 && Previous_Count == 1)
                    {
                        DeleteNoteBT.Visible = false;

                        if (!string.IsNullOrEmpty(NoteTitleTB.Text) && !string.IsNullOrWhiteSpace(NoteTitleTB.Text))
                        {
                            if (NoteTitleTB.Text != Current_Note.Name)
                            {
                                if (!Duplicate_Note(NoteTitleTB.Text))
                                {
                                    Note_Changes.Remove(Current_Note.Name);
                                    Note_Changes.Add(NoteTitleTB.Text, NoteBodyTB.Text);
                                    Current_Note.Name = NoteTitleTB.Text;
                                    Current_Note.Text = NoteTitleTB.Text;
                                }

                                else
                                {
                                    MessageBox.Show("Duplicate note titles are not allowed.", "Duplicate Note Title", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    Note_Changes[Current_Note.Name] = NoteBodyTB.Text;
                                }
                            }

                            else
                            {
                                Note_Changes[Current_Note.Name] = NoteBodyTB.Text;
                            }
                        }

                        // Cant differentiate easily so just assume a safe general case of the following
                        // Set the previous to current and the current to null
                        if (Previous_Note != null)
                        {
                            Previous_Note.Font = RegularFont;
                        }

                        if (Current_Note != null)
                        {
                            Current_Note.Font = RegularFont;
                        }

                        Previous_Note = Current_Note;
                        Current_Note  = null;

                        NoteTitleTB.Clear();
                        NoteTitleTB.Enabled = false;
                        NoteBodyTB.Clear();
                        NoteBodyTB.Enabled = false;
                    }

                    // Going from deselected to selected
                    // Happens when selecting another item after the last item is deselected or going from nothing to selecting an item.
                    else if (Current_Count == 1 && Previous_Count == 0)
                    {
                        DeleteNoteBT.Visible = true;

                        // Cant differentiate easily so just assume a safe general case of the following
                        // Set the previous to null and the current to the selected item

                        if (Previous_Note != null)
                        {
                            Previous_Note.Font = RegularFont;
                        }

                        Previous_Note = null;

                        Current_Note      = NotesLV.SelectedItems[0];
                        Current_Note.Font = BoldFont;

                        NoteTitleTB.Text    = Current_Note.Name;
                        NoteTitleTB.Enabled = true;

                        try
                        {
                            NoteBodyTB.Text = Note_Changes[Current_Note.Name];
                        }
                        catch
                        {
                        }

                        NoteBodyTB.Enabled = true;
                    }

                    _lock = false;
                }
            }
        }